模板中 operator++ 上未解析的外部符号 [英] Unresolved external symbol on operator++ in template

查看:70
本文介绍了模板中 operator++ 上未解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
为什么我会收到未解析的外部符号"错误什么时候使用模板?

我正在制作一个链表.我正在使用外部迭代器.Iterator 类是一个模板,我正在 Iterator.h 中实现我的方法.

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.

这是模板:

#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* ()
{

}
 }

当我尝试编译时收到此错误消息:1>list_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall list_1::Iterator<double>::operator++(void)"

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?

谢谢!

推荐答案

如果我正确阅读了您的错误消息,您的 Iterator 将 Node 作为输入,但是您正在应用 double 对它不适用.为了支持non-Node类型,你需要专门化Iterator.

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)"
                                         ^^^^^

这篇关于模板中 operator++ 上未解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆