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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:59:21+00:00 2026-06-02T09:59:21+00:00

very quick question, let’s say I have a template: template <class T> class foo

  • 0

very quick question, let’s say I have a template:

template <class T>
class foo {

 private:
   T SubFoo;
  ...

};

And then I have things like:

 foo < foo < int > > myFoo;

which works fine. In this case, myFoo would have a member called myFoo.SubFoo which would have the type foo < int >.

I would like to have a pointer in myFoo.SubFoo that points to myFoo. I don’t know how to properly call this, a class-member pointer of SubFoo that points to the whole mother class, myFoo. Is this possible? I tried to include the declaration:

template <class T>
class foo {

 private:
  ...
   T SubFoo;
   foo< foo < T > >* p2mother; 
  ...

};

But this does not seem to work.

In general, what I am doing is setting up a recursive structure. It’s quite easy to pass communication down the recursion but I am finding trouble going “upwards”. Maybe I am designing this wrongly in the first place.

Thanks a lot!

  • 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-02T09:59:23+00:00Added an answer on June 2, 2026 at 9:59 am

    The more general case (this works in g++):

    template <class T>
    struct foo {
    
     //...
     T SubFoo;
     foo* p2mother; 
     //...
    };
    
    foo< int > simple;
    foo< foo< int > > complex;
    
    int main() {
    
      simple.p2mother = &simple;
      complex.p2mother = &complex;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

very quick question. I have a href link like so in my template. <a
quick and very basic newbie question. If i have list of dictionaries looking like
Quick question: If I have a very large function/sub in a class that is
This is just an out of curiosity question. Let's say you have a database
I have very small and quick question. Is it neceseary for all the developers
Quick question: I have a very busy form going on that I have developed
Quick question. I have a client with an HTML based website which ranks very,
I have a very quick question - Is it possible to modify the source
I have a very quick question about how to utilise Zend_Db_Table with user specific
A quick question: the Android docs say very clearly that Messenger is an alternative

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.