Reputation: 1354
I was reading about templates here http://publib.boulder.ibm.com/ when i saw this piece of code that really confused me:
template<class T> class Y { };
template<class T, int i> class X {
public:
Y<T> f(char[20][i]) { return x; };
Y<T> x;
};
template<template<class> class T, class U, class V, class W, int i>
void g( T<U> (V::*)(W[20][i]) ) { };
int main()
{
Y<int> (X<int, 20>::*p)(char[20][20]) = &X<int, 20>::f;
g(p);
}
Could you please explain to me what this line means?
Y<int> (X<int, 20>::*p)(char[20][20]) = &X<int, 20>::f;
I just cant grasp the meaning of it. Thanx!
Upvotes: 0
Views: 68
Reputation: 13529
Y<int> (X<int, 20>::*p)(char[20][20]) = &X<int, 20>::f;
declares a member function pointer p
to a member function of class X<int, 20>
that accepts a pointer to array of 20 char
s, and returns Y<int>
. Then this pointer is initialized with member function f
of class X<int, 20>
Upvotes: 3