Returning pointer to a struct defined inside a class, multiple scope operators
my header file for a basic binary tree includes the following:
Code:
template<typename T>
class Btree{
// OVERVIEW: a binary tree with flexible structure that is not sorted
private:
struct node { //a container object
node *left; //left and right tree
node *right;
T *o; // pointer to object of node
};
public:
node *root; //pointer to the root of the tree (NULL if empty)
node* insert (node *parent, T *child, int child);
//MODIFIES: this
//EFFECTS: creates a node that stores a pointer to the new child
// and returns the pointer to the node of the new child
// the integer child is either 0, for left child,
// or anything else for right child
// void printTree (node * root);
//EFFECTS: takes the root of a tree and prints the tree's
// coordinates
Btree(); //ctor
Btree(){} //dtor
};
#include "btree.cpp"
-----------------------------------------------------------------------------------------
my .cpp looks like this, and not that it is included at the bottom of my header to avoid template compiler errors:
Code:
template <typename T>
Btree<T> :: node * Btree<T>::insert (node *parent, T *child, int child)
{
node *np = new node;
np-> o = child;
np->left = NULL;
np->right = NULL;
if (child == 0)
parent->left = np;
else
parent->right = np;
return np;
}
however, i get the following compiler error:
btree.cpp:3: error: expected constructor, destructor, or type conversion before ‘*’ token
i'm compiling on 4.1.2 of the g++ compiler
Can anyone help!?!?! http://im.cprogramming.com/images/smilies/frown.png