I set up pdcurses correctly. I made a little test program that runs just fine. It's my classes that are the problem. Here's a piece of my code (shield your eyes!):
utility.h
// utility.h - for general useful things like random numbers
#ifndef _UTILITY_
#define _UTILITY_
// Forward declare everything I need here. Bad idea?
class Dungeon;
//class Creature;
class Level;
class RNG
{
public:
static int randInRange(int min, int max);
static int roll(std::string dice);
};
class DEBUG
{
public:
static void checkpoint();
};
class StringOp
{
public:
template<class T>
static std::string toString(const T& t)
// not my code!
{
std::ostringstream stream;
stream << t;
return stream.str();
}
template<class T>
static T fromString(const std::string& s)
// not my code
{
std::istringstream stream (s);
T t;
stream >> t;
return t;
}
};
class Color
{
public:
enum Colors
{
BLACK=0,
DARK_BLUE,
DARK_GREEN,
TEAL,
DARK_RED,
PURPLE,
BROWN,
LIGHT_GRAY,
DARK_GRAY,
BLUE,
GREEN,
CYAN,
RED,
PINK,
YELLOW,
WHITE,
SELECTED
};
static void initColorPairs();
static void color(int color);
};
#endif
utility.cpp
// utility.cpp
#include "headers.h"
int RNG::randInRange(int min, int max)
{
if(max < min) max = min;
int number = (rand()%(max-min+1))+min;
}
int RNG::roll(std::string roll)
{
int dQuantity, dSize; // Number and size of dice
int divider; // where the 'd' is in the string
int number = 0; // the random number
divider = roll.find("d");
if(divider == std::string::npos) return 0;
dQuantity = StringOp::fromString<int>(roll.substr(0,divider));
dSize = StringOp::fromString<int>(roll.substr(divider+1));
for(int i=0; i<dQuantity; i++)
{
number += randInRange(1,dSize);
}
return number;
}
void DEBUG::checkpoint()
{
mvaddstr(0,0,"DEBUG CHECKPOINT!");
getch();
}
void Color::initColorPairs()
{
init_pair(0,COLOR_BLACK,COLOR_BLACK);
for(int i=1; i<=15; i++)
{
init_pair(i,i,COLOR_BLACK);
}
init_pair(SELECTED,BLACK,WHITE);
}
void Color::color(int color)
{
attron(COLOR_PAIR(color));
}
headers.h
// headers.h ties all the project files together.
#ifndef _HEADERS_
#define _HEADERS_
#include <stdlib.h>
#include <curses.h>
#include <time.h>
#include <string>
#include <vector>
#include <cmath>
#include <sstream>
#include <iostream>
#include "utility.h"
#include "entity.h"
#include "item.h"
#include "creature.h"
#include "player.h"
#include "ai.h"
#include "dungeon.h"
#include "menu.h"
#endif
errors:
c:\jake\projects\roguelike\utility.cpp(4) : error C2653: 'RNG' : is not a class or namespace name
c:\jake\projects\roguelike\utility.cpp(10) : error C2653: 'RNG' : is not a class or namespace name
c:\jake\projects\roguelike\utility.cpp(20) : error C2653: 'StringOp' : is not a class or namespace name
c:\jake\projects\roguelike\utility.cpp(20) : error C2065: 'fromString' : undeclared identifier
c:\jake\projects\roguelike\utility.cpp(20) : error C2062: type 'int' unexpected
c:\jake\projects\roguelike\utility.cpp(22) : error C2653: 'StringOp' : is not a class or namespace name
c:\jake\projects\roguelike\utility.cpp(22) : error C2065: 'fromString' : undeclared identifier
c:\jake\projects\roguelike\utility.cpp(22) : error C2062: type 'int' unexpected
c:\jake\projects\roguelike\utility.cpp(31) : error C2653: 'DEBUG' : is not a class or namespace name
c:\jake\projects\roguelike\utility.cpp(37) : error C2653: 'Color' : is not a class or namespace name
c:\jake\projects\roguelike\utility.cpp(45) : error C2065: 'SELECTED' : undeclared identifier
c:\jake\projects\roguelike\utility.cpp(45) : error C2065: 'BLACK' : undeclared identifier
c:\jake\projects\roguelike\utility.cpp(45) : error C2065: 'WHITE' : undeclared identifier
c:\jake\projects\roguelike\utility.cpp(48) : error C2653: 'Color' : is not a class or namespace name
It isn't pretty and it's mostly uncommented, but I'm hoping that the problem is so obvious and trivial that you'll recognize it immediately. This is only one file that is having trouble. Of course, it works.... well, compiles at least, in Dev-C++, so the problem might not be in my code at all.