错误信息如下:

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. python安装——Windows平台

    刚刚申请博客,第一次写随笔,记录下自己最近的学习情况,希望自己能够不断的学习,不断的丰富自己~ 最近刚开始学python,记录一下,希望大家相互学习,批评指正~ 1.下载python:https:// ...

  2. 更改AngularJS的语法解析符号

    // 更改AngularJS的语法解析符号 app.config(function ($interpolateProvider) { $interpolateProvider.startSymbol( ...

  3. CloudStack核心类ApiServlet、ApiServer、ApiDispatcher、GenericDaoBase源码分析

    ApiServlet 首先从整体上看下ApiServlet,Outline视图如下, 一.注意@Inject依赖的是javax.inject.jar,它和spring的@Autowired的区别在于使 ...

  4. LeetCode_Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  5. WebApi 能支持Session

    由于项目实际需要,我希望让WebApi服务也能支持Session,所以便查找资料按照网上的方法开始着手实验. 然后就有了以下的代码,主要是说让WebApi支持Session,要重写Global.asa ...

  6. SHELL种类,版本及选择

    SHELL种类,版本及选择 凡是使用 *INX 的人,不论是作为 login shell 还是编程,多少都要接触到 Shell.经过多年的发展, Shell 的种类繁多.除了我们熟悉的 sh.ksh. ...

  7. c++智能指针《二》 std::tr1::shared_ptr

    转载http://www.cnblogs.com/kadinzhu/archive/2011/12/12/2284826.html 看<effective c++>,作者一直强调用std: ...

  8. JSplitPane详解

    摘自http://blog.163.com/xiexueyong1987@126/blog/static/1262673422010102711295541/ JSplitPane详解 pasting ...

  9. POJ 1631 Bridging signals DP(最长上升子序列)

    最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...

  10. 第17讲- UI常用组件之ImageView图片浏览

    第17讲 UI常用组件之ImageView图片浏览 二.图片浏览ImageView ImageView就是一个用来显示图片的视图: ImageView常见属性 常见属性 对应方法 说明 android ...