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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:41:05+00:00 2026-05-15T05:41:05+00:00

I am attempting to compile the following template based code in VC++ 2005. #include

  • 0

I am attempting to compile the following template based code in VC++ 2005.

    #include <iostream>
using namespace std;


/*
 * T is a template which maps an integer to a specific type.
 * The mapping happens through partial template specialization.
 * In the following T<1> is mapped to char, T<2> is mapped to long
 * and T<3> is mapped to float using partial template specializations
 */
template <int x>
struct T
{
public:
};

template<>
struct T<1>
{
public:
    typedef char xType;
};


template<>
struct T<2>
{
public:
    typedef long xType;
};

template<>
struct T<3>
{
public:
    typedef float xType;
};

// We can easily access the specific xType for a specific T<N>
typedef T<3>::xType x3Type;

/*!
 * In the following we are attempting to use T<N> inside another
 * template class T2<R>
 */

template<int r>
struct T2
{
    //We can map T<r> to some other type T3
    typedef T<r> T3;
    // The following line fails
    typedef T3::xType xType;
};

int main()
{
    T<1>::xType a1;
    cout << typeid(a1).name() << endl;
    T<2>::xType a2;
    cout << typeid(a2).name() << endl;
    T<3>::xType a3;
    cout << typeid(a3).name() << endl;
    return 0;
}

There is a particular line in the code which doesn’t compile:

typedef T3::xType xType;

If I remove this line, compilation goes fine and the result is:

char
long
float

If I retain this line, compilation errors are observed.

main.cpp(53) : warning C4346: 'T<x>::xType' : dependent name is not a type
    prefix with 'typename' to indicate a type
    main.cpp(54) : see reference to class template instantiation 'T2<r>' being compiled
main.cpp(53) : error C2146: syntax error : missing ';' before identifier 'xType'
main.cpp(53) : error C4430: missing type specifier - int assumed. Note: C++ does not    support default-int

I am not able to figure out how to make sure that T::xType can be treated as a type inside the T2 template. Any help is highly appreciated.

  • 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-15T05:41:06+00:00Added an answer on May 15, 2026 at 5:41 am

    Since T3 in your template class depends on the template parameter, the compiler can’t known for sure what T3::xType will refer to (that might depend on the actual type r in each instantiation T2<r>).

    To tell the compiler that T3::xType will be a type, you need to add the typename keyword:

    typedef typename T3::xType xType;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: #include<iostream> using namespace std; class sample { int a; int
I'm attempting to get the following code from nmdepend to compile const std::string Bfd::packageName(const
Attempting to compile the following code under Qt SDK 4.7.4 for Desktop - MinGW
While attempting to cross-compile ICU using android-ndk-r7 in Linux, the following error occurs after
In attempting to compile ICU49 using Android NDKv7b, I ran into the following: /home/tim/icu49/icu/source/common/putil.cpp:
I'm attempting to following the tutorials found here: http://www.ifadey.com/2010/06/crud-using-jquery-and-codeigniter/ My code is updated to
I am attempting to compile C code that utilizes the following within GNU readline.
I am attempting to compile some code, but am running into some problems that
I am attempting to compile a c++ class using gcc. Due to the nature
I am trying to start using cython and and attempting to compile my first

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.