gpt4 book ai didi

c++ - undefined symbol 首先被引用

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:19 25 4
gpt4 key购买 nike

我是 C++ 的新手,我正在学习模板类和动态内存分配,所以如果这里有愚蠢的错误,我深表歉意。我不能确切地说出这段代码中的问题是什么,但我似乎无法让编译器给我任何东西,除了..

Undefined                       first referenced
symbol in file
indexList<timecard>::operator=(indexList<timecard> const&)/var/tmp//ccgqjCOv.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
template <class T>
indexList<T>& indexList<T>::operator=(const indexList<T> &other) const{
if(this != &other){
name = other.name;
ssn = other.ssn;
hours = other.hours;
payRate = other.payRate;
numOfDependents = other.numOfDependents;
unionMem = other.unionMem;

delete list;

list = new T[maxSize];

*list = *(other.list);
}//end if

return *this;
}

最佳答案

{ 之前的最后一个 const 限定符不属于那里。

我不确定为什么会出现这个特定的错误,因为函数实际上已经定义了,但是所有赋值 name = 等都是非法的,因为 this常量。但是,复制赋值运算符是一个特殊函数,编译器确实不希望看到这个签名。

关于c++ - undefined symbol 首先被引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22599484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com