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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:02:42+00:00 2026-05-26T02:02:42+00:00

I have a class template <typename T> struct Trait { typedef std::false_type IsGood; };

  • 0

I have a class

template <typename T>
struct Trait { typedef std::false_type IsGood; };

template <>
struct Trait<int> { typedef std::true_type IsGood; };

A call like this fails to compile on MSVC 2010

template <typename T, typename Enable = void> class Foo;

template <typename T>
class Foo <T, std::enable_if<typename Trait<T>::IsGood::value>::type>
{};

// This fails as well
template <typename T>
class Foo <T, typename std::enable_if<Trait<T>::IsGood::value>::type>
{};

// And this fails horribly
template <typename T>
class Foo <T, typename std::enable_if<typename Trait<T>::IsGood::value>::type>
{};

while

template <typename T>
class Foo <T, typename std::enable_if<std::is_same<std::true_type, 
    typename Trait<T>::IsGood>::value>::type>
{};

works — why?

The error message is:

main.cpp(12): error C2039: 'type' : is not a member of 'std::tr1::enable_if<_Test>'
          with
          [
              _Test=false
          ]
main.cpp(12): error C2146: syntax error : missing ',' before identifier 'type'
main.cpp(12): error C2065: 'type' : undeclared identifier
main.cpp(13): error C2976: 'Foo' : too few template arguments
  • 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-26T02:02:43+00:00Added an answer on May 26, 2026 at 2:02 am

    You’re using typename at wrong place. This is correct:

    template <typename T>
    class Foo <T, typename std::enable_if<Trait<T>::IsGood::value>::type>
    {};        // ^^^^^^^ here should be typename
    

    Now it compiles fine: http://ideone.com/0SwO9

    But you’re using typename as:

    template <typename T>
    class Foo <T, std::enable_if<typename  Trait<T>::IsGood::value>::type>
    {};                        //^^^^^^^ wrong place
    

    Trait<T>::IsGood::value is not a type, So you cannot apply typename on it.

    GCC error message is very much clear:

    prog.cpp:12:62: error: type/value mismatch at argument 1 in template parameter list for ‘template<bool <anonymous>, class _Tp> struct std::enable_if’

    See yourself : http://ideone.com/9ujJv

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

Sidebar

Related Questions

I have the following templated class structure struct TraitA{}; struct TraitB{}; template<typename trait> struct
I have a class A: template <typename T, int I> struct A {}; and
Say I have a templated class like template <typename T> struct Node { //
I have a class like template <class T> struct A{ template <class U> A(U
I have a template class like below. template<int S> class A { private: char
I got class with template methods that looks at this: struct undefined {}; template<typename
I have the following code: template<typename T, typename Allocator = std::allocator<T> > class Carray
lets say i have a templated class template <typename T> struct Widget { //generalized
I have the following class template<typename hi_t, typename lo_t> struct int_t { hi_t hi;
Basically, I have lots of differently typed structs like this: typedef struct { char

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.