I have a problem trying to create a method that its type its a private variable of her class:

foo.h

template <class T> class Foo {
  private:
    struct Node {
      T value;
      Node * following;
    }

    Node * bar( const T & elem );
}

foo.cpp

template <class T> Node * bar( const T & elem );

But Node doesn't exists in foo.cpp, because is a private variable of the class Foo foo.h.

How can I fix it?

有帮助吗?

解决方案

In foo.cpp you are specifying the return type and name of the function incorrectly. Node comes from the class Foo so you need to qualify it with Foo<T>::. Same goes with the member function bar:

template <class T>
typename Foo<T>::Node* Foo<T>::bar( const T & elem );
//       ^^^^^^^^      ^^^^^^^^
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top