Template subclass pointer problem

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();

    }; //-end-subclass------------------------------

    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()
{
    // ... Delete children ...

    // I allocate each leaf, so I need to delete them
    std::set< Leaf* >::iterator it = m_leaves.begin(); // <-- bad
    std::set< Leaf* >::iterator endit = m_leaves.end(); // <-- bad
    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 ) // <-- bad
{
    // Insert stuff...
}

I get a compilation error: expected constructor, destructor, or type conversion before ‘*’ token

- , ? , , .

Ps. , , , , , .

. Quadtree → QuadTree typo

+3
4

typename std::set< Leaf* >::iterator it = m_leaves.begin(); 
typename std::set< Leaf* >::iterator endit = m_leaves.end();

std:: set , , . gcc 4.5.0 .

:

template <class value_type>
typename QuadTree<value_type>::Leaf* QuadTree< value_type >::Insert ( const value_type & _x )
{
    // Insert stuff...
}

- QuadTree. , QuadTree, .

: QuadTree.

+4

typename, :

typename std::set< Leaf* >::iterator it = m_leaves.begin();

, Leaf value_type . , Leaf value_type of Quadtree< value_type >, :

template <class value_type>
Quadtree< value_type >::Leaf * Quadtree< value_type >::Insert ( const typename Quadtree< value_type >::value_type & _x )
+1

, std::set< Leaf* >::iterator - :

 typename std::set< Leaf* >::iterator it = ...
 typename std::set< Leaf* >::iterator endit = ...

Leaf () , , Leaf , , std::set<Leaf*> iterator. , iterator - std::set< Leaf* >, typename.

, return vale Leaf, , , . :

template <class value_type>
typename Quadtree< value_type >::Leaf * Quadtree< value_type >::Insert (...) ...
+1

... .

Leaf - , .

class Leaf //-Subclass--------------------------
{
    friend class QuadTree< value_type >;
protected:
    value_type* m_data;

    Leaf();
    ~Leaf();

}; //-end-subclass------------------------------
  • protected , , public. , - , , ,
  • Sacred 3: Destructor, Copy Constructor Assignment Operator, . protected, ( ), .

: ?

class Leaf
{
public:
  explicit Leaf(value_type data): mData(data) {}

private:
  value_type mData;
};

.

, QuadTree : .

+1

Source: https://habr.com/ru/post/1753284/