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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:08:09+00:00 2026-06-02T21:08:09+00:00

I have a question about extracting typedef’d information from a class inherited through templates.

  • 0

I have a question about extracting typedef’d information from a class inherited through templates. To illustrate my question, consider the following simple example:

#include <iostream>

class A1{
public:
    void print(){ printf("I am A1\n"); };
};
class A2{
public:
    void print(){ printf("I am A2\n"); };
};

class B1{
public:
    typedef A1 A;
};

class B2{
public:
    typedef A2 A;
};

template<class b>
class C{
    typedef class b::A AA;
    AA a;
public:
    void Cprint() {     a.print();  };
};

int main()
{
    C<B1> c1;
    c1.Cprint();

    C<B2> c2;
    c2.Cprint();
}

Class C takes a class (either B1 or B2) as a template parameter. Both B1 and B2 have a tyepdef called A (which is class A1 and A2, respectively). At compile time, class C should be able to figure out which of the two “A” classes is being used by the “B” class. When I compile with g++, the above code works perfectly. However, when I compile it with Intel’s icpc, I get the following error:

test.cpp(24): error: typedef "A" may not be used in an elaborated type specifier
    typedef class b::A AA;
                     ^
    detected during instantiation of class "C<b> [with b=B1]" at line 33

Is there another way to achieve a similar effect? Of course, my actual code is much more complicated and there are reasons I want the classes structured in this way. There are also reasons I want to compile with icpc and not g++.

Thanks in advance.
Carl

  • 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-02T21:08:12+00:00Added an answer on June 2, 2026 at 9:08 pm

    Try changing:

    template<class b>
    class C{
        typedef class b::A AA;
        AA a;
    public:
        void Cprint() {     a.print();  };
    };
    

    to:

    template<class b>
    class C{
        typedef typename b::A AA;
        AA a;
    public:
        void Cprint() {     a.print();  };
    };
    

    b::A is a dependent type (it is dependent on what type is used for b).

    FYI, the original posted code failed to compile with VS2008 and VS2010.

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

Sidebar

Related Questions

I have question about try, catch and finally in Java. Consider the following scenario:
I have a question about extracting a part of a string. For example I
I have a question about using streams in .NET to load files from disk.
I have a question about using os.execvp in Python. I have the following bit
I have question about throw. How will the throw work in the following code?
I have a question about the extraction of multiple values from a data.frame in
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body

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.