c++ - 进行重载运算符时发生C++错误,未定义

标签 c++ compiler-errors operators

我得到这个错误

myDate.cpp:(.text+0x160): undefined reference to `myTime::operator==(myTime const&) const'

这是我第一次使用头文件和重载运算符进行编码,因此将不胜感激。这是我的myDate代码:http://pastebin.com/i4CLvWBS header :http://pastebin.com/ULircg5q

错误来自theTime==date.getTime());
这是我的重载运算符的一个示例
bool myDate::operator==(const myDate &date) const
{
  return (year == date.getYear() && 
          month==date.getMonth() && 
          day==date.getDay() && 
          theTime==date.getTime());
}

时间是来自另一个名为myTime的文件,我不知道如何正确定义运算符,以防万一您需要使用新的myTime来解决此问题:vWr5zwDq只需在pastebin中跟进

我还确保myTime.cpp正确链接,因为myTime.cpp链接到myTime.h,而myTime.h链接到myDate.h,myDate.h链接到myTime.cpp,当我从myDate.h中删除#include "myTime.h"时,我的代码打破了那个文件。
#include "myTime.h"  #include "myTime.h"   #include "myDate.h"
myTime::myTime()     class myDate()        myDate::myDate()

最佳答案

您还必须为类bool operator==(myTime const&) const;声明/定义适当的myTime

如果这样做,请确保myTime.cpp与其余代码正确链接。

有关此错误消息以及链接实际含义的更多信息,请参见此处:
What is an undefined reference/unresolved external symbol error and how do I fix it?

关于c++ - 进行重载运算符时发生C++错误,未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28791866/

相关文章:

git - 使用Maven编译使用旧版本Giraph的项目

c++ - 铛+ libc++ : combination of make_tuple with make_shared leads to early object destruction

c++ - 通过轮换 boost 2 个文件的日志记录

c++ - OpenCV propId 值位于何处?

java - Java if-then 树中缺少返回语句错误

compiler-errors - 英特尔Fortran灾难性错误: Token too long, max is 7194

r - ggplot2 和其他函数之间的加号 (R)

php - less < 运算符无法识别我是否设置了类似字符串 PHP

perl - Perl中<=>(小于,等于,大于)的含义?

c++ - Windows 和 Linux 中的毫秒级随机种子