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

  • Home
  • SEARCH
  • 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 6693633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:00:22+00:00 2026-05-26T06:00:22+00:00

So I have a class which holds a struct inside its private variables and

  • 0

So I have a class which holds a struct inside its private variables and inside this struct I have an array where the size of the array is only determined after the construction of the class.

template <typename T> 
class btree {

  public:
    btree(size_t maxNodeElems);
    ~btree() {}

  private:
    // The details of your implementation go here
    size_t maxNodeElems;
    struct node {

      list <T> elements;
      node lvl[];

    };

};

Firstly, do I have to make it so its node * lvl and how do I call the variables inside this struct? Is it the same as a private variable, so whenever I use it inside one of the functions in btree class I can call it be btree.lvl or is it btree->node->lvl or is there a special way to do this?

Also, my array has to be of maxNodeElems+1 if someone can help me, that’d be much appreciated!

  • 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-26T06:00:23+00:00Added an answer on May 26, 2026 at 6:00 am

    You are just declaring the type, not an actual object of that type. You need to make your struct declaration public and the object private:

    template <typename T> 
    class btree {
    
      public:
        btree(size_t maxNodeElems);
        ~btree() {}
    
        struct node {   // <- this is just a declaration of a private inner-class
          list <T> elements;
          node lvl[];
        };
    
      private:
        size_t maxNodeElems;
        node*  memberNode;   // <- this is the actual private member
    
    };
    

    You can create objects of that type from outside:

    btree<A>::node* n = new btree<A>::node;
    

    For accessing members, you can have public getters & setters in your btree class:

    class btree {
    public:
       node* getNode()
       {
          return memberNode;
       }
       //...........
       //...........
    };
    

    EDIT:

    The following works for me (initializing the member):

    template <typename T> 
    class btree {
    
      public:
        btree()
        {
           memberNode = new btree<T>::node;
        }
        ~btree() {}
    
        void init()
        {
           memberNode->lvl = new node[10];
        }
    
        struct node {   // <- this is just a declaration of a private inner-class
          list <T> elements;
          node* lvl;
        };
    
      private:
        size_t maxNodeElems;
        node*  memberNode;   // <- this is the actual private member
    
    };
    
    int _tmain(int argc, _TCHAR* argv[])
    {
       btree<char> b;
       b.init();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which holds strings. I declared them like this: private String
I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is
I have a class which looks something like this: public class Test { private
I have defined a class in C++ which holds an array of scalars of
In my code I have a class lipid which holds three bead s: struct
I have this ConstantData class which holds my JSON indexes, I need to pass
I have class(Customer) which holds more than 200 string variables as property. I'm using
I have one base class which holds a map for function pointers like this
I have a .NET class which holds a simple array of strings available via
Suppose I have a LimitedValue class which holds a value, and is parameterized on

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.