Unresolved external symbol on operator++ in template [duplicate]

谁都会走 提交于 2019-12-12 14:21:53

问题


Possible Duplicate:
Why do I get “unresolved external symbol” errors when using templates?

I am making a linkedList. I am using an external iterator. The Iterator class is a template, and I am implementing my methods in the Iterator.h.

Here is the template:

#pragma once

#include "Node.h"

 namespace list_1
 {

template<typename T>
class Iterator
{
public:
    Iterator<T> (Node<T> *np);
    void operator++();
    bool is_item();
    T operator* ();

private:
    Node<T>* n;
};

template<typename T>
Iterator<T>::Iterator (Node<T> *np)
{

}

template<typename T>
void Iterator<T>::operator++()
{

}

template<typename T>
bool Iterator<T>::is_item()
{
    return false;
}

template<typename T>
T Iterator<T>::operator* ()
{

}
 }

I get this error message when I try to compile: 1>list_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall list_1::Iterator<double>::operator++(void)"

Plus about seven other similar errors in the whole project.

Am I doing something wrong here? Or is it something else I am doing wrong?

Thanks!


回答1:


If I read your error message correctly, you Iterator takes Node<T> as input, however you are applying double to it which is not applicable. To support non-Node<T> type, you need to specialize Iterator<T>.

public: void __thiscall list_1::Iterator<double>::operator++(void)"
                                         ^^^^^


来源:https://stackoverflow.com/questions/14514379/unresolved-external-symbol-on-operator-in-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!