BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #44907同步于 2010/10/17
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

高手帮忙看看为什么加上析构函数就报错

littlefish
2010/10/17镜像同步3 回复
record头文件 #ifndef _RECORD_H #define _RECORD_H #include <iostream> #include <string> using std::istream; using std::ostream; using std::string ; class record { friend ostream& operator << (ostream &out,const record &r); public: record(int p,double b,string s):price(p),bookisbn(b),title(s){} // ~record(); private: int price; double bookisbn; string title; }; #endif main文件 #include "record.h" using std::cout; using std::endl; ostream & operator << (ostream &out ,const class record & r) { out<<r.price<<"\t"<<r.bookisbn<<"\t"<<r.title; return out; } int main() { record child(10,012006,"The world is flat"); cout<<child<<endl; } 把~record前面的注释去掉链接是就报错
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
purevirtual机器人#1 · 2010/10/17
只有声明没有定义 ~record () {} 这样试试 【 在 littlefish (小鱼) 的大作中提到: 】 : record头文件 : #ifndef _RECORD_H : #define _RECORD_H : ...................
yzhuqing机器人#2 · 2010/10/17
在。h文件里声明了析构函数,但是没有实现它。 有两种方法解决: 1.实现析构函数。可以像1楼那样提供一个空实现。 2.不声明,编译器会提供一个默认析构函数。 【 在 littlefish 的大作中提到: 】 : record头文件 : #ifndef _RECORD_H : #define _RECORD_H : ...................
littlefish机器人#3 · 2010/10/18
谢谢楼上两位!