So the following code works great:
void function() { }
std::cout << typeid(decltype(function)).name() << '\n';
but the following code doesn't compile:
struct object {
void function() { }
}
std::cout << typeid(decltype(object::function)).name() << '\n';
Why?
The member function has a type, just as the normal function has a type right? I would assume it looks like this:
void func(object*, void)
The strange thing is, I can get the pointer just fine with:
decltype(&object::function)
That ends up being this:
void (__thiscall object::*)(void)
If I can get the pointer to it, why can't I get the type of it? Just like I can with the normal function. I tried to remove the pointer after getting the pointer to member function type:
template <typename T>
struct remove_pointer { using type = T; }
template <typename T>
struct remove_pointer<T*> { using type = T; }
std::cout << typeid(remove_pointer<decltype(&object::function)>::type).name() << '\n';
It doesn't remove the pointer, but instead of failing compilation, it just prints out the same thing that it does when I don't try to remove the pointer.
This is all very confusing, can someone help me make sense of why I can't access the actual type of a member function?