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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:51:20+00:00 2026-06-02T08:51:20+00:00

second template question of the day, what a n00b: I have a template class:

  • 0

second template question of the day, what a n00b:

I have a template class:

template <class T>
class foo{
  private:
     //...
     T SubFoo;
     //...

};

I also have a class called myClass. I would like to have objects of the kind:

foo<myClass> myObject;

But, and here’s the problem, I would like to be able to get a pointer to myObject from myObject.SubFoo. That means that one of the members of the class myClass should be an instantiation of the template class foo.

So I can do:

class myClass{
   //...
   foo<myClass>* point2myClass;

}

However, it seems that this does not work because

./foo.h:103: error: ‘foo::SubFoo’ has incomplete type

When defining myClass, the program finds the line

   foo<myClass>* point2myClass;

It goes to the defintion of foo and it finds:

     T SubFoo;

but T, in this case myClass, has not yet been defined (that is what the program was doing!), so it doesn’t know what T is, hence the error.

If I interchange the order of declarations, it will also fail because “foo” will not be defined.

How can I make this work??

Thanks a million!

  • 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-02T08:51:22+00:00Added an answer on June 2, 2026 at 8:51 am

    The following code, should definitely work just fine. If your code is different, please specify where.

    template < typename T >
    struct A
    {
        T x;
    };
    
    struct X
    {
        A<X>* x;
    };
    
    int main()
    {
        X a;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(second question today - must be a bad day) I have a dataframe with
I have a 30 second audio file and I would like to get callbacks
I have a template class Foo that takes two (or more) template arguments. I
Continuing from my last question C++ template class map I have implemented the function
Okay, simple template question. Say I define my template class something like this: template<typename
if i have a template function: template<class T, class S> void foo(T t, S
I have a class expecting a two parameters template, like this: template<template <class, class>
Second question of the day but hopefully simple, I just need to change the
I have a question concerning using the toggle function. I have a template that
I would like to override custom user template in my Drupal 7 installation. The

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.