문제

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