0

I have a very simple template class.

#pragma once
#include <iostream>

template <class T>
class Test
{
protected:
    class Node
    {
    public:
        Node(Node& node) {}
    protected:
        virtual Node* copyNode(Node&);
    private:
    };
};

template <class T>
Test<T>::Node* Test<T>::copyNode(Test<T>::Node& node)
{
    return new Test<T>::Node(node);
}

I use it in the main program as follows.

#include "Test.h"
using namespace std;

int main()
{
    Test<int> tree;
    getchar();
}

I get a syntax error C2061: "identifier 'Node'".

Both the declaration and the implementation are in the same header file (the linker has problems with template classes). I am using Visual Studio 2015.

What is the proper way of implementing the copyNode method without writing it inline?

Igor Ševo
  • 5,459
  • 3
  • 35
  • 80

1 Answers1

1

typename are missing:

template <class T>
typename Test<T>::Node* Test<T>::Node::copyNode(typename Test<T>::Node& node)
{
    return new Test<T>::Node(node);
}
Jarod42
  • 203,559
  • 14
  • 181
  • 302