1
#include <iostream>

struct A
{
    static void Func1() {}
    static void Func2() {}
};

int main()
{
    struct A a;

    std::cout << A::Func1 << std::endl;
    std::cout << A::Func2 << std::endl;
}

Output:

1
1

I would think this would give me the pointer addresses for where the instructions for the static member function lives but it doesn't seem to do that.

I am running on gcc 4.8.2 on ubuntu.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Nathan Doromal
  • 3,437
  • 2
  • 24
  • 25
  • 7
    `A::Func1` is the name of a function, which will decay to a function pointer, which can be converted to a boolean, which is always `true` (since the pointer is not a null pointer). Probably a duplicate question. – dyp Jun 11 '15 at 17:19
  • While this seems impractical, I am experimenting if it's possible to detect whether a struct has a particular function defined using SFINAE. – Nathan Doromal Jun 11 '15 at 17:20
  • 3
    @NathanDoromal: What happens by default when you stream a function (pointer) to `std::cout` has literally nothing to do with SFINAE or whether a struct has a particular function defined. – Lightness Races in Orbit Jun 11 '15 at 17:21
  • Related/duplicate: [c++ static method output using cout is always 1](http://stackoverflow.com/q/13050673/) – dyp Jun 11 '15 at 17:21
  • @dyp As with most things C++, MSVC is the exception to the rule :) Unless you disable language extensions, the function pointers will convert to `void *` instead of `bool`, and the code above will print addresses. – Praetorian Jun 11 '15 at 17:40

0 Answers0