At the time of insanity, I decided to write a C ++ template class for quadrants. I came across some strange compiler error that I don't understand about subclasses and template pointers. I found some hacking work, but I wondered if anyone could shed some light on why my code is not compiling ...
I am on Linux creating with scons using g ++
My code looks something like this: I have a class of templates for describing a tree and a subclass describing "leaves":
template <class value_type>
class QuadTree
{
public:
class Leaf //-Subclass--------------------------
{
friend class QuadTree< value_type >;
protected:
value_type* m_data;
Leaf();
~Leaf();
};
QuadTree();
~QuadTree();
Leaf * Insert ( const value_type & _x );
protected:
QuadTree( Quadtree< value_type >* _parent );
QuadTree< value_type >* m_parent;
QuadTree< value_type >* m_children[4];
std::set< Leaf* > m_leaves;
};
The first pointer problem I get is in the QuadTree destructor:
template <class value_type>
QuadTree< value_type >::~QuadTree()
{
std::set< Leaf* >::iterator it = m_leaves.begin();
std::set< Leaf* >::iterator endit = m_leaves.end();
for(;it != endit; ++it)
delete *it;
}
When compiling, I get this error: expected ';' before ‘it’and expected ';' before ‘endit’. Another pointer error is indicated in the definition of the Insert function:
template <class value_type>
Leaf * QuadTree< value_type >::Insert ( const value_type & _x )
{
}
I get a compilation error: expected constructor, destructor, or type conversion before ‘*’ token
- , ? , , .
Ps. , , , , , .
. Quadtree → QuadTree typo