2009-05-20 67 views
13

有没有人知道模板类中超出声明模板方法的语法。超出模板类中模板方法的声明模板定义

例如:

template<class TYPE> 
class thing 
{ 
public : 
    void do_very_little(); 

    template<class INNER_TYPE> 
    INNER_TYPE do_stuff(); 
}; 

第一种方法的定义:

template<class TYPE> 
void thing<TYPE>::do_very_little() 
{ 
} 

我该怎么做第二个, “do_stuff”?

+0

您的意思是声明do_stuff作为成员字段?假设你真的想要声明一个方法,它的参数是什么? – outis 2009-05-20 05:32:14

+0

您需要在类声明中的do_stuff之后加上括号 – 2009-05-20 05:37:22

回答

29
template<class TYPE> 
template<class INNER_TYPE> 
INNER_TYPE thing<TYPE>::do_stuff() 
{ 
    return INNER_TYPE(); 
} 

试试这个。