Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a definition of function declared in template class returning pointer to struct object?

Tags:

c++

templates

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

How proper definition should look like ?

like image 774
Bouncer00 Avatar asked Mar 19 '23 17:03

Bouncer00


1 Answers

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

Doing that:

template<typename T> typename Foo<T>::Some_struct* Foo<T>::function()
like image 65
Deduplicator Avatar answered Apr 09 '23 00:04

Deduplicator