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

  • Home
  • SEARCH
  • 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 7963567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:38:14+00:00 2026-06-04T05:38:14+00:00

struct X{}; template<class T> decltype(X() == int()) f(T const&){ return true; } int main(void)

  • 0
struct X{};

template<class T>
decltype(X() == int()) f(T const&){ return true; }

int main(void) {
  X x;
  f(x);
}

Why, just why? There is no operator== defined anywhere!

I really want to understand what’s going on here, to provide a detailed bug report on MS Connect. My journey to insanity began around here in the Lounge<C++> chat room…

(Note: Neither GCC nor Clang accept this code.)

Oh, and btw, adding a private X(int) ctor causes the compilation to fail:

struct X{
    X(){}
private:
    X(int);
};

template<class T>
decltype(X() == int()) f(T const&){ return true; }

int main(void) {
  X x;
  f(x);
}

Output:

1>src\main.cpp(12): error C2248: 'X::X' : cannot access private member declared in class 'X'
1>          src\main.cpp(4) : see declaration of 'X::X'
1>          src\main.cpp(1) : see declaration of 'X'
  • 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-04T05:38:14+00:00Added an answer on June 4, 2026 at 5:38 am

    What version of MS VC++ are you using?

    For whatever it may be worth, VC++11 Beta rejects your code with:

    trash.cpp(8): error C2893: Failed to specialize function template ''unknown-type' f(const T &)'
              With the following template arguments:
              'X'
    

    I’m not sure that’s what I’d call the most helpful or informative error message ever, but it is rejecting the code.

    Under the circumstances, I’d guess filing a bug report is probably going to accomplish little (if anything). The response I’d expect would be essentially: “Already fixed in VC++11. Upgrade when you can.”

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

Sidebar

Related Questions

Given: template<class T> struct test { void foo(int b); void testFunc( int a )
I have the following code: template <class T> struct pointer { operator pointer<const T>()
struct A { void f(int x) {} }; struct B { template<typename T> void
Is there direct way to do the following: template < class > struct f
template<typename T> struct A { auto func() -> decltype(T::func()) { return T::func(); } };
I have a template class btree and have defined a struct Node in the
I have a class like template <class T> struct A{ template <class U> A(U
Is it possible to specialize this template for any basic_string's? template<class T> struct X
I have code: #include <cstdio> template<template<typename...> class> struct Foo { enum { n =
template<int x> struct A { template<int y> struct B {};. template<int y, int unused>

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.