如何编写模板类中声明的函数定义,返回指向struct对象的指针?

Bou*_*r00 4 c++ templates

我有这样的代码:

template<typename T> class Foo
{
   struct Some_struct
   {
      T object;
      Some_struct* next;
   };
public:
   Some_struct* function(); //declaration of my function
};
template<typename T> Some_struct* Foo<T>::function() //this definition is wrong
{
    //something inside
    return pointer_to_Some_struct;
}
Run Code Online (Sandbox Code Playgroud)

应该如何正确定义?

Ded*_*tor 7

您忘记将适当的范围添加到返回类型.

这样做:

template<typename T> typename Foo<T>::Some_struct* Foo<T>::function()
Run Code Online (Sandbox Code Playgroud)