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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:30:20+00:00 2026-05-27T11:30:20+00:00

I want to define a type name in a templated class that I can

  • 0

I want to define a type name in a templated class that I can use elsewhere to refer to the type of a member in the class.

template <class T>
class CA
{
public:
    //typedef typename T::iterator iterator_type;
    typedef typename T ElementType1; // compile error on this line
    //typedef T ElementType2;

    T m_element;
};

and use it like this:

template <class T>
class CDerived : public CBase<typename T::ElementType1>
{
 //...
};

and declare objects like:

typedef CDerived<CA> MyNewClass;

Is this not possible? I have some code that compiles correctly under VS2010 but not under Xcode that uses the line:

typedef typename T ElementType1;

Apparently the compiler is expecting a qualified name after typename but I don’t see how there can be one for the template type.

I dont understand the difference between ElementType1 and ElementType2 in this context.

I looked at many questions on stack overflow but most seemed to refer to only the kind of declaration like iterator_type in my example.

  • 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-27T11:30:21+00:00Added an answer on May 27, 2026 at 11:30 am

    The compiler already knows T is a type (class T), so you don’t need the typename qualifier in the first case. OTOH, the compiler doesn’t know in advance that T::ElementType1 is a type; it depends on what T ends up being.

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

Sidebar

Related Questions

Hi I've got a static member of a templated class that I want defined
I want to use partial specialization for a template class so that all children
I want to define a class that supports __getitem__ , but does not allow
I want to define a class method that has access to a local variable.
I want to define a generic class in c++ that allow to execute my
I'm writing a templated C++ generic container class that can optionally maintain its contents
Say I have a macro, FOO(name), and some template class Bar<> that takes one
I have a class that contains a private typedef and several member functions: class
I want to use class member functions as callbacks, I don't use libsigc, because
I want to define a ref type variable, like this: SomeType v=null; and this

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.