// this stuff is in a separate file.
namespace prog
{
enum progState
{
goodState,
badState,
otherState,
};
} // namespace
// class header file
namespace prog
{
class Program
{
private:
static progState ProgramState;
public:
Program();
~Program();
void InitProgram();
void ProgramGo();
};
}// namespace
// the cpp file...
namespace prog
{
Program::Program()
{
// set the state to good
ProgramState = goodState;
// do some init that might modify it.
// all references to ProgamState are good in the constructor.
}
Program::~Program()
{
// clean up...
}
void Program::InitProgram()
{
if(ProgramState == goodState)
{
// this is where it gets messed up...
// ProgramState is good to the compiler with nothing within this block
// add any code to it like
std::cout << "InitProgram" << std::endl;
// and the compiler spits back that ProgramState is undefined reference
// in any function of said class will result with the same error
}
}
void Program::ProgramGo()
{
if(ProgramState == goodState)
{
// this is where it gets messed up...
// ProgramState is good to the compiler with nothing within this block
// add any code to it like
std::cout << "ProgramGo" << std::endl;
// and the compiler spits back that ProgramState is undefined reference
// in any function of said class will result with the same error
}
}
} // namespace
This is driving me nuts when one way it compiles fine and then I modify the code with CodeLite I get the error. I don't know what's going on here. I have never seen this problem before. I think my logic is pretty sound here.
The Solution I found on another web site would add a prototype, or forward casting which ever is preferred wording, in the cpp files namespace. I don't understand why this is needed. I may try to compile this code on another compiler