错误信息如下:

1>t2.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Date::Date(void)" (??0Date@@QAE@XZ),该符号在函数 "class Date __cdecl operator+(class Date const &,class Date const &)" (??H@YA?AVDate@@ABV0@0@Z) 中被引用

1>C:\Users\Chengyao\Documents\Workspaces\Visual Studio 2012\Projects\Test11\Debug\Test12.exe : fatal error LNK1120: 1 个无法解析的外部命令

代码如下:

C/C++
code


?




1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35


#include


using
 namespace std;


class
 Date{


    
int m_y;


    
int m_m;


    
int m_d;


public
:


    
Date();


    
Date(int y,int m,int d){


        
m_y=y;


        
m_m=m;


        
m_d=d;


    
}


public
:


    
void set(int y,int m,int d){


        
m_y=y;


        
m_m=m;


        
m_d=d;


    
}


    
friend Date operator+(const Date& d1,const Date& d2){


        
Date d;


        
d.set(d1.m_y+d2.m_y,d1.m_m+d2.m_m,d1.m_d+d2.m_d);


        
return d;


    
}


    
void display(){


        
cout<<"The date is:"<<m_y<<","<<m_m<<","<<m_d<<endl;


    
}


};


int
 main(){


    
Date d1(2009,11,10);


    
d1.display();


    
Date d2(1,1,1);


    
d2.display();


    
(d1+d2).display();


}



解决办法:




1

2

3


Date()


{


};
//改成这样

构造函数没有定义。







作者:gcy77 发表于2014-3-12 15:16:26 原文链接
阅读:68 评论:0 查看评论

[原]C++关于运算符重载的程序报错error…的更多相关文章

  1. 运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory

    运行编译后的程序报错  error while loading shared libraries: lib*.so: cannot open shared object file: No such f ...

  2. android程序报错“error launching activity com.android.ddmlib.shellcommandunresponsiveexception”的解决方式

    今天在调试android程序的时候,因为是NDK开发,要先编译.so库再打包下载到android模拟器,所以花费的时间比較长.控制台就会报例如以下错误: error launching activit ...

  3. debug运行java程序报错

    debug运行java程序报错 ERROR: transport error 202: connect failed: Connection timed out ERROR: JDWP Transpo ...

  4. C++走向远洋——47(第十二周、运算符重载基础程序、阅读)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  5. Window7中Eclipse运行MapReduce程序报错的问题

    按照文档:http://www.micmiu.com/bigdata/hadoop/hadoop2x-eclipse-mapreduce-demo/安装配置好Eclipse后,运行WordCount程 ...

  6. eclipse运行hadoop程序报错:Connection refused: no further information

    eclipse运行hadoop程序报错:Connection refused: no further information log4j:WARN No appenders could be foun ...

  7. WinDbg抓取程序报错dump文件的方法

    程序崩溃的两种主要现象: a. 程序在运行中的时候,突然弹出错误窗口,然后点错误窗口的确定时,程序直接关闭 例如: “应用程序错误” “C++错误之类的窗口” “程序无响应” “假死”等 此种崩溃特点 ...

  8. 记录微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

    微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function 这个报错是在将数组对象通过 ...

  9. 小程序-报错 xxx is not defined (已解决)

    小程序-报错 xxx is not defined (已解决) 问题情境: 这样一段代码,微信的小程序报错 is not defined 我 wxml 想这样调用 //wxml 代码 <view ...

随机推荐

  1. ZOJ 3818 Pretty Poem

    暴力模拟 细节处理很重要... #include <iostream> #include <cstring> #include <cstdio> using nam ...

  2. 用UseMiddleware扩展方法注册中间件类

    用UseMiddleware扩展方法注册中间件类 .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件 ...

  3. 再谈Redirect(客户端重定向)和Dispatch(服务器端重定向)

    这是两个常常被放在一起进行比较的概念,今天对这两个概念再重新回顾一下,前者发生在客户端(浏览器),后者发生在服务器端,因此也有人把前者称为客户端重定向,把后者称为服务器端重定向,虽然对于后者这种称谓并 ...

  4. 鼠标点击变色 lvha

    a标签有四个"状态"的先后过程是:a:link ->a:hover ->a:active ->a:visited.另外,a:active不能设置有无下划线(总是有 ...

  5. libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结

    说法一: 我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫 ...

  6. Linux下装VirtualBox

    一:下载 进入VirtualBox的下载地址:https://www.virtualbox.org/ 点击左侧的download, 选择适合自己系统的版本,我的是红帽,故选择: 进行下载. 二:安装 ...

  7. input元素有padding间距,所以使用box-sizing来保持宽度不超出父元素

    http://vicbeta.com/code/2013/04/24/phone-over-width.html 手机web开发资料少,原创解决方案Mark. 手机页面遇到一个横竖屏切换时出现的问题. ...

  8. HDu 5433 Xiao Ming climbing (BFS)

    题意:小明因为受到大魔王的诅咒,被困到了一座荒无人烟的山上并无法脱离.这座山很奇怪: 这座山的底面是矩形的,而且矩形的每一小块都有一个特定的坐标(x,y)和一个高度H. 为了逃离这座山,小明必须找到大 ...

  9. Compiled Language vs Scripting Language

    Referrence: Blog Compiled Languages Example: C, C++, Java Source code needs to be compiled into bits ...

  10. hdu 1506 Largest Rectangle in a Histogram(单调栈)

                                                                                                       L ...