I tried to compile the following code.
#include <iostream>
class Base
{
public:
template <typename T>
T fun()
{
std::cout<<"CALLED!"<<std::endl;
return T();
}
};
class Derived : public Base
{
};
template<class T>
T (Derived::*func_ptr)() = &Base::fun;
int main()
{
Derived d;
///how to call?
}
To my surprise, this compiled in both clang and gcc. This gives me the idea that somehow we should be able to call fun
by func_ptr
. However, I cannot think of what the syntax should be to call the function by this pointer. What is the syntax for it and how is it explained?
Also another thing is, I cannot think of a reason for this to compile. Where is this behavior defined in C++ standard?