How to write a definition of a function declared in a template class that returns a pointer to a struct object?

I have a code like this:

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

What should the correct definition look like?

+4
source share
1 answer

You forgot to add the correct scope to the return type.

Doing this:

template<typename T> typename Foo<T>::Some_struct* Foo<T>::function()
+7
source

All Articles