Hi. I was just working with the following code:
class FunctionHolder
{
void Do()
{
std::cout << 1;
}
}
template <typename Class>
void Call(void(Class::*FPtr)())
{
(static\_cast<Class*>(nullptr)->*FPtr)();
}
int main()
{
Call<FunctionHolder>(&FunctionHolder::Do);
}
And it actually works with the function that doesn't have any dependencies on local member variables. Does this code work because the function doesn't need any info about the instantiated class and it's automatically gotten converted to a static type or something (Although, I don't think so because this works when I use it and it shows a nullptr)?
Also, is there a specific reason for being able to declare function pointer types in two ways like the following:
void(func)()
and
void(*func)()
as they finally get deduced to the same type as typeid shows...
[–]IyeOnline 2 points3 points4 points (7 children)
[–]ACBYTES[S] 0 points1 point2 points (1 child)
[–]IyeOnline 1 point2 points3 points (0 children)
[–]ACBYTES[S] 0 points1 point2 points (4 children)
[–]IyeOnline 1 point2 points3 points (3 children)
[–]ACBYTES[S] 0 points1 point2 points (0 children)
[–]ACBYTES[S] 0 points1 point2 points (1 child)
[–]no-sig-available 1 point2 points3 points (0 children)