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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:19:36+00:00 2026-06-07T04:19:36+00:00

struct C { int Foo(int i) { return i; } typedef decltype(C::Foo) type; };

  • 0
struct C
{
    int Foo(int i) { return i; }

    typedef decltype(C::Foo) type;
};

Since there is no such type as a member function type (there isn’t, is there?), I expect C::type to be int (int).

But the following won’t compile using the Visual C++ 2012 RC:

std::function<C::type> f;

So what type is decltype(C::Foo)?

  • 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-07T04:19:39+00:00Added an answer on June 7, 2026 at 4:19 am

    The code is ill-formed: there are only a few ways that a member function name (e.g. C::Foo) can be used, and this is not one of them (the complete list of valid uses can be found in the C++ language standard, see C++11 §5.1.1/12).

    In the context of your example, the only thing you can really do is take the address of the member function, &C::Foo, to form a pointer to the member function, of type int (C::*)(int).

    Since the code is ill-formed, the compiler should reject it. Further, it yields inconsistent results depending on how C::Foo is used; we’ll look at the inconsistency below.

    Please report a bug on Microsoft Connect. Alternatively, let me know and I am happy to report the issue.


    If you have a type but you don’t know what the type is, you can find out the name of the type by using it in a way that causes the compiler to emit an error. For example, declare a class template and never define it:

    template <typename T>
    struct tell_me_the_type;
    

    Then later, you can instantiate this template with the type in which you are interested:

    tell_me_the_type<decltype(C::Foo)> x;
    

    Since tell_me_the_type hasn’t been defined, the definition of x is invalid. The compiler should include the type T in the error it emits. Visual C++ 2012 RC reports:

    error C2079: 'x' uses undefined struct 'tell_me_the_type_name<T>'
    with
    [
        T=int (int)
    ]
    

    The compiler thinks that C::Foo is of type int (int). If that is the case, then the compiler should accept the following code:

    template <typename T>
    struct is_the_type_right;
    
    template <>
    struct is_the_type_right<int(int)> { };
    
    is_the_type_right<decltype(C::Foo)> x;
    

    The compiler does not accept this code. It reports the following error:

    error C2079: 'x' uses undefined struct 'is_the_type_right<T>'
    with
    [
        T=int (int)
    ]
    

    So, C::Foo both is of type int (int) and is not of type int (int), which violates the principle of noncontradiction. 🙂

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

Sidebar

Related Questions

I have this C code : #include<stdio.h> typedef struct { int foo; } MyStruct;
typedef struct { int A; int B; char* C; // problem is here }foo;
I have following code #include <stdio.h> #include<ctype.h> typedef struct { int Type; int Type2;
Consider the following: struct A { typedef int foo; }; struct B {}; template<class
Is there a side effect in doing this: C code: struct foo { int
struct Foo { int data; Foo() = default; Foo(const Foo& arg) = default; };
Say I have an object: struct Foo { int bar_; Foo(int bar) bar_(bar) {}
Given this class: class C { private: struct Foo { int key1, key2, value;
Question 1 I have a struct like, struct foo { int a; char c;
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int

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.