// myclass.h
class MyClass
{
publicint AFunction();
protected:
int root;
};
//==========
// myclass.cpp
#include "myclass.h"
int AFunction() // notice, forgot the scope operator, therefore this function is global
{
return root; // ERROR, 'root' doesn't exist in the global namespace
}
int MyClass::AFunction() // here we have the scope operator -- so we're in MyClass
{
return root; // OK, 'root' exists in MyClass so no error here.
}
and it's being called in another header file which includes the class
template<class elemType>
void guessingTreeType<elemType>::CreateTree(nodeType<elemType> &rootNode)
{
root = &rootNode; <- here is where i get the error
}
I think I've read about this before (assuming that guessingTreeType is a binaryTreeType). I think you have to explicitly tell it where to find root but I forget the details of why. Try this->root.