2014-01-20 52 views
0

我读到有关模板这里http://publib.boulder.ibm.com/当我看到这一段代码,真糊涂我:复杂的模板函数

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); 
} 

可否请你给我解释一下这行的意思?

Y<int> (X<int, 20>::*p)(char[20][20]) = &X<int, 20>::f; 

我只是不能把握它的含义。感谢名单!

+0

的成员函数f @jrok非常挑剔! –

+0

@jrok好吧,那是指向2维数组地址的常量指针,对吗? –

+0

@Joseph我知道,但它是我的宠物狗:) – jrok

回答

3
Y<int> (X<int, 20>::*p)(char[20][20]) = &X<int, 20>::f; 

声明了一个成员函数指针p到接受指针的20个char列数组,并返回Y<int>X<int, 20>类的成员函数。然后这个指针初始化为类X<int, 20>