运算符=函数上的C++gcc错误
C++ gcc error on operator= function
函数定义
const circularLinkedList<Tp>& operator=(const circularLinkedList<Tp>& otherList);
导致错误的行,错误消息指的是从nodeType…开始的行327。。。。
template <class Tp>
nodeType<Tp>* circularLinkedList<Tp>&::operator=(const circularLinkedList<Tp>& otherList)
来自gcc编译器的错误消息是:
circularLinkedList.h:327: error: invalid declarator before â&â token
circularLinkedList.h:327: error: expected initializer before â&â token
我认为我在某个地方定义这个方法时犯了某种语法错误。我该怎么着手修理它呢?谢谢
你能为我们发布更多的代码吗?你能解释一下nodeType是什么吗?
下面看起来像是一个函数定义:
template <class Tp>
nodeType<Tp>* circularLinkedList<Tp>&::operator=(const circularLinkedList<Tp>& otherList)
但是,首先,声明说它返回一个const circularLinkedList<Tp>&
。此外,您不希望在::
之前有&
。它需要是类型的名称,而不是指向该类型变量的指针或引用。如果你想要这种行为,你需要使用一个代理类。
所以它应该是这样的:
template <class Tp>
const circularLinkedList<Tp>& circularLinkedList<Tp>::operator=(const circularLinkedList<Tp>& other)
哪个几乎总是以return *this;
在第一个代码块中,显示的是方法声明,而不是函数定义。在第二个代码块中,将显示方法定义的标头。
方法声明:返回const circularLinkedList<Tp>&
方法定义:返回nodeType<Tp>*
。
您没有定义您声明的方法。您正在定义一些尚未声明的方法。
定义的标题应该是:
const circularLinkedList<Tp>& circularLinkedList<Tp>::operator=(const circularLinkedList<Tp>& otherList)
相关文章:
- 在分配和发布递增循环迭代器时C++无限循环(gcc 错误?
- GCC 警告和 gcc 错误消息之间的区别
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- typedef名称与可变模板参数名称一致时出现GCC错误
- 条件变量:wait_for.gcc错误
- 不可复制类数据成员的统一初始化导致gcc错误
- 在类中将不完整类型的unique_ptr初始化为 nullptr 时编译 gcc 错误
- GCC-7:错误:无法识别的命令行选项"-M64"
- C++ GCC 错误:"sqrtl"不是"std"的成员
- 在联盟中,不愿命名的未命名结构的成员是错误或GCC错误
- 尾随返回类型中带有 SFINAE 的 GCC 错误
- 与lambda一起使用虚拟继承在初始化列表中捕获此问题的GCC错误
- 通过指向成员的指针对嵌套访问进行编译时评估期间出现 GCC 错误
- 从成员变量访问静态 constexpr 成员,GCC 错误?
- std::seed_seq编译错误(GCC错误?)
- GCC 错误:如果已知函数正常返回,则函数可能是属性"pure"的候选者
- iostream GCC错误,转换为boost::filesystem::iostream for Windows
- GCC错误?链式方法,断开序列点
- 是否存在GCC错误:默认std :: function
- GCC 错误错误的 ELF 类:ELFCLASS64,尽管有 -m64 标志