Template and function pointer

I was reading a book about game development. I saw this line of code. I tried to copy and and understand whats going on here is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class A
{
public:
	template<class T>
	void Hello(void(T::*func)())
	{
		func(); // Not working. Error term does not evaluate to function taking 0 argument
	}
};

class B
{
public:
	 void funcA()
	{
		std::cout << "Hello world" << std::endl;
	}


};

void main()
{
	A a;
	a.Hello(&B::funcA);
	

}


What sort of template is this? a template class declared on a function but not declared on the class? Im confuse. Also why cant I call the func() on the Hello()? I can do that on regular function pointer why not in here? Thanks
Last edited on
Got it working using

1
2
T t;
(t.*func)()


Is there a way to use the -> operator to this? this is just hard to read
Topic archived. No new replies allowed.