Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 924601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:22:52+00:00 2026-05-15T19:22:52+00:00

In a moment of madness, I decided to write a quadtree C++ template class.

  • 0

In a moment of madness, I decided to write a quadtree C++ template class. I’ve run into some weird compiler error that I don’t understand with regard to subclasses and pointers to templates. I’ve found some hacky work arounds, but I wondered if anyone could shed some light on why my code wouldn’t compile…


I’m on Linux, building with scons, using g++

My code looks something like this, I have a template class to describe 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;

};

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 I compile I get this error: expected ';' before ‘it’ and expected ';' before ‘endit’.
The other pointer error is in the Insert function definition:

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

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

Anyone know why I’m getting these errors? I’ve got fixes for the problems, but I want to know why I can’t do it this way.

Ps. I’ve edited the code to show it here, so it is possible I’ve missed something I thought utterly irrelevant.

Edit. Fixed Quadtree -> QuadTree typo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:22:53+00:00Added an answer on May 15, 2026 at 7:22 pm

    You need

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

    The type of std::set depends on another template argument and you have to tell the compiler that this is actually a type. gcc 4.5.0 produces a better error message.

    The second error is similar:

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

    Leaf is a inner class to QuadTree. You need to name it as such and you need to specify the type of the QuadTree as the inner class depends on the template parameter.

    Another thing: You have a typo in QuadTree in many places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have a class that requires information from another class, but
So at the moment I have a simple reminder app that you enter some
There is a moment in my app, that I need to force to show
at the moment we're using SVN (yeah, I know that's shame :)) and we're
At the moment I have an C# console application that exposes Web Services through
At the moment I'm working with a git repo, locally so I don't to
Ignore for the moment that not all browsers support LocalStorage. Would it be possible
At this moment we are keeping all Entities and Mappings into same assembly. Our
at the moment i am trying to write a unreal amount of data out
At the moment I am in the following /public_html/v3/football/admin/new.php Inside that new.php, i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.