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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:49:55+00:00 2026-05-26T01:49:55+00:00

I am using a SFINAE mechanism to deduce a type. Resolve<T>::type is deduced to

  • 0

I am using a SFINAE mechanism to deduce a type. Resolve<T>::type is deduced to T if class T doesn’t contain yes and it’s deduced to MyClass if it contains yes.

class MyClass {};

template<typename>
struct void_ { typedef void check; };

template<typename T, typename = void>
struct Resolve { typedef T type; };

template<typename T>
struct Resolve <T, typename void_<typename T::yes>::check> {
    typedef MyClass type;
};

Now, I have the simple test classes as,

struct B1 { typedef int yes; }; // 1
struct B2 { typedef int yes; }; // 2
struct D1 {};  // 3
struct D2 : B1 {};  // 4
struct D3 : B1, B2 {}; // 5 <----

According to the logic following should be the result for above tests:

  1. Resove<B1>::type = MyClass
  2. Resove<B2>::type = MyClass
  3. Resove<D1>::type = D1
  4. Resove<D2>::type = MyClass
  5. Resove<D3>::type = MyClass or compiler error (due to ambiguity between B1, B2)

Strangely, in test case (5) it doesn’t happen so. The result is,

Resolve<D3>::type = D3;

Can anyone explain, what magic is happening specially for multiple inheritance ? Not getting compiler error is a standard compliant behavior ? Here is the demo.

  • 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-26T01:49:56+00:00Added an answer on May 26, 2026 at 1:49 am

    Why would you expect a compiler error? You know SFINAE stands for Substitution Failure Is Not An Error right?

    When you substitute T by D3 the expression becames ambiguous. Due to SFINAE, this failure is not considered an error and your specialization is simply removed as a candidate. It’s all about NOT getting a compiler error.

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

Sidebar

Related Questions

I tried to implement an SFINAE using bool (unlike popular void_ trick ): template<typename
Using SFINAE, i can detect wether a given class has a certain member function.
I'm using my class as a template parameter of one of its parent class,
Using C#, I need a class called User that has a username, password, active
I want to detect existence of a specific member function for a class, using
I'm trying to use SFINAE to detect if a class has an overloaded member
Following on from this answer , it seems these constructors: template<class U, class V>
I have a class with a template parameter which should decide which of two
Is it a bug in Visual C++ 2010 or right behaviour? template<class T> T
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I

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.