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 9173551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:36:21+00:00 2026-06-17T16:36:21+00:00

One small question about the c++ templates mechanism. Suppose we have a class called

  • 0

One small question about the c++ templates mechanism. Suppose we have a class called Point. Now suppose “Data” is a template class/container, containing only T (template) data member.
That is, “Data” looks more or less like this:

Template <class T>
class Data {
T dMember;
……..
};

Now suppose someone using this class in the main.cpp file and preforms the following declaration:

Data<Data<Point>> d;

I’m trying to understand completely how the object created looks like. I was trying to use the complier to get into the class call but to no avail. I know that Data need to initialize Data so it calls itself one time, but what it really does there? Is there a constructor being activated?

Thank you,
Guy

  • 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-06-17T16:36:23+00:00Added an answer on June 17, 2026 at 4:36 pm

    I know that Data need to initialize Data so it calls itself one time, but what it really does there? Is there a constructor being activated?

    Data does not really call itsef one time. This is because the inner Data and the outer Data are two different classes. In general, if the compiler sees Data<Data<Point>>, it first recognizes the inner part, i.e. Data<Point>. It then instantiates the template, meaning it creates a class having the properties described by the template. It’s important to realize that Data is not a class, but a template that can be used to create a whole bunch of classes. Each of those classes is different from the others, they are different types and have no real relation to each other. So Data<Point> is just one instanitation of the template, and its a class that has the same properties like, say,

    class Foo {
      Point dMember;
      ...
    };
    

    I’ll just call it Foo. The Compiler then sees Data<Data<Point>>, which could as well be Data<Foo>. It instantiates the template again, this time using Foo (i.e. the class it got from the first instantiation) as the parameter. It gets another class, in principle completely independent of the first one, except it has a member of the first instantiation’s type:

    class Bar {
      Foo dMember;
      ...
    };
    

    Thats all. Data does not call itself, Data does not even exist as a type. The constructors being called in initalization are Bar’s constructors, which in turn will call Foo’s constructors. The constructor thingy you defined in Data is no real constructor, because anything that lies inside a class template is a template itself. So its a constructor template, and if you call Foo’s and/or Bar’s constructor the compiler uses that template to instantiate the actual constructors.

    Data is just a blueprint for the compiler to build real classes (and member functions, if needed), it never gets out there to play or to call or initialize anything.

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

Sidebar

Related Questions

I have one small question about the pumping lemma for regular languages - is
Generally, I have a question about ORM(s), and the best way for managing enterprise/small
Another small question about STL: i have Dictionary: map <string,vector <Wordy> > Dictionary; using
I'm learning the MVVM pattern with a new(small) project, and I've one question about
This question is server oriented. I have a hosted server (a rather small one,
I have in my homework some question about data structure: I have elements which
One more question about Django concerning localization of javascript files. Django provides a small
It's a question about InvalidOperationException with message Class member X is unmapped. One of
I have a small question about 3D. What follows is an example of my
I have a question about Ember routing and controllers. I've just written a small

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.