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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:23:44+00:00 2026-06-16T11:23:44+00:00

It’s not the concept as a whole, but rather one of the methods it

  • 0

It’s not the concept as a whole, but rather one of the methods it uses to determine if a class has an n data-member. Here is the full code; an ordinary use of SFINAE for member detection.

template <typename T>
struct has_X {
    struct Fallback { int X; };
    struct Derived : T, Fallback {};

    template <typename U, U> struct S;

    template <typename C> static char (&f(S<int Fallback::*, &C::X> *))[1];
    template <typename C> static char (&f(...))[2];

    public:
        const static bool value = sizeof(f<Derived>(0)) == 2;
};

The part where Derived inherits from both Fallback and T confuses me because when we do the overload of f, &C::X is &Derived::X. But shouldn’t this overload always be chosen because isn’t Derived guaranteed to have X since it inherits from Fallback which has that data-member?

Maybe I’m overlooking something. However, this single piece of code has shown and taught me things I never knew, so maybe there is something to this. What I would expect is for that overload to always be chosen (not the one with the ...) because Derived should always have X since it inherits from Fallback. But this is not the case. Can someone please explain why?

  • 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-16T11:23:45+00:00Added an answer on June 16, 2026 at 11:23 am

    Fallback has one data member named X, but Derived will have two if T also has a member named X, in which case Derived::X cannot be taken unambiguously. So if T does not have X, the first overload is used, and if T has X, the second more general version is used. This is why you can tell these cases apart depending on the size of their return types.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.