C++ 我得到了错误';TList<;T>;::运算符=';:无法将函数定义与现有声明相匹配。visual studio community 2017

C++ 我得到了错误';TList<;T>;::运算符=';:无法将函数定义与现有声明相匹配。visual studio community 2017,c++,c++14,C++,C++14,我正在犯错误 TList::operator=':无法将函数定义与 现有声明。visual studio社区2017。错误代码:C2244 错误在问题的底部,我试图定义复制分配运算符: #include <iostream> #include <utility> #include "tnode.h" // Declaration of class TList template <typename T> cla

我正在犯错误

TList::operator=':无法将函数定义与 现有声明。visual studio社区2017。错误代码:C2244

错误在问题的底部,我试图定义复制分配运算符:

    #include <iostream>
    #include <utility>
    #include "tnode.h"

    // Declaration of class TList

    template <typename T>
    class TList
    {
        friend class TListIterator<T>;


    public:
        TList();        // create empty linked list
        TList(T val, int num);// create list with num copies of val
        ~TList();               // destructor
        TList(const TList& L);      // copy constructor
        TList operator=(const TList& L);// copy assignment operator
        TList(TList && L);      // move constructor
        TList operator=(TList && L);// move assignment operator



    private:
        Node<T>* first;     // pointer to first node in list
        Node<T>* last;      // pointer to last node in list
        int size;           // number of nodes in the list
        static T dummy; // dummy object, for empty list data returns
        //  assuming type T has default construction

    };




    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <cmath>
    using namespace std;
    template <typename T> 
    TList<T>& TList<T>::operator = (const TList& L)
    {
         size = L.size;
         return *this;
    }
#包括
#包括
#包括“tnode.h”
//类别列表的声明
模板
类列表
{
友元类标识符;
公众:
TList();//创建空链表
TList(T val,int num);//使用val的num个副本创建列表
~TList();//析构函数
TList(const TList&L);//复制构造函数
TList运算符=(const TList&L);//复制赋值运算符
TList(TList&&L);//移动构造函数
TList运算符=(TList&&L);//移动赋值运算符
私人:
Node*first;//指向列表中第一个节点的指针
Node*last;//指向列表中最后一个节点的指针
int size;//列表中的节点数
static T dummy;//dummy对象,用于返回空列表数据
//假设类型T具有默认构造
};
#包括
#包括
#包括
#包括
使用名称空间std;
模板
TList&TList::operator=(常量TList&L)
{
尺寸=L.尺寸;
归还*这个;
}

首先,您将函数声明为

TList operator=(const TList& L);
但你把它定义为

TList<T>& TList<T>::operator = (const TList& L)
TList&TList::operator=(const-TList&L)
请注意,返回类型不同(定义返回一个引用)


其次,您可能试图在单独的源文件中定义模板函数。请参阅。

首先,您将函数声明为

TList operator=(const TList& L);
但你把它定义为

TList<T>& TList<T>::operator = (const TList& L)
TList&TList::operator=(const-TList&L)
请注意,返回类型不同(定义返回一个引用)


其次,您可能试图在单独的源文件中定义模板函数。参见。

TList运算符=(const TList&L)等。TList不是完整类型;名单is@UKMonkey它在类定义内,但不在类定义外。随着尾随返回,它甚至更奇怪
auto-TList::operator=(…)->TList&
有效
TList operator=(const-TList&L)等。TList不是完整类型;名单is@UKMonkey它在类定义内,但不在类定义外。随着尾随返回,它甚至更奇怪<代码>自动TList::运算符=(…)->TList&
有效