/*
struct SplayNode
{
SplayNode *left, *right;
int key;
};
SplayNode *root, *nullNode;
*/
class SplayTree
{
public:
SplayTree()
{
nullNode = new SplayNode;
nullNode->left = nullNode->right = nullNode;
root = nullNode;
}
void rotateLeft(SplayNode *&node)
{
SplayNode *p = node->right;
node->right = p->left;
p->left = node;
node = p;
}
private:
struct SplayNode
{
SplayNode *left, *right;
int key;
};
SplayNode *root, *nullNode;
};
During comilation 'class SplayTree' has to see declaration for
'SplayNode'. To fix it put forward declaration of "struct SplayNode;"
before 'class SplayTree'.
Member function definitions are compiled "as if" they
immediately followed the class. The declaration is compiled
when it is seen, however, which means that the declaration of
this function is only legal if the compiler has seen the symbol
SplayNode. (Note that it can be a forward declaration: you
simply add:
class SplayNode ;
at the top of the class definition.
> private:
> struct SplayNode
> {
> SplayNode *left, *right;
> int key;
> };
> SplayNode *root, *nullNode;
> };
--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[which struct - please keep context]
> Could someone give me some tips about how to declare the struct?
As normal, you just have to move the member definitions of the "client'
class into a source file which include the header with the required
struct declaration.
--
Ian Collins.
But whay when i put the struct in the private, it's wrong?
The compiler doesn't know what it is until it has finished parsing the
class declaration. Either do as I said and put the containing class
member function definitions in a source module, forward declare the
nested struct or put your private parts before your public ones.
--
Ian Collins.