【c++程序】拷贝构造函数
2015-10-16 21:17
344 查看
/********************************************************/ /**************---About 析构函数-------**************/ /**************---Author: Tibruce Zhao-----**************/ /**************---Date: 2015/10/15------***************/ /********************************************************/ #include<iostream> using namespace std; class F { public: F(int n=0,int d=1);//默认构造函数 ~F(); /*拷贝构造函数,如果没有写拷贝构造函数,编译器会为每个类自动写一个, *完成所有成员的逐个复制。*/ F(const F &f):n(f.n-1),d(f.d+1)//初始化不给值,默认0; {cout<<this<<"F(F f}"<<endl;} void print(bool newline=true); void print(bool newline=true)const;//构成重载 void input(); private: int n; int d; }; F::F(int n,int d):n(n),d(d)//成员变量初始值 { cout<<this<<",F("<<n<<','<<d<<")"<<endl; } F::~F() { cout<<"~F()"<<n<<'/'<<d<<endl; } void F::print(bool newline) const { cout<<"ONLY READ"<<n<<'/'<<d; if(newline) cout<<endl; } void F::print(bool newline) { cout<<"FREE"<<n<<'/'<<d; if(newline) cout<<endl; } F func(F x) { return x; } int main() { F a(3,5); cout<<"******************************"<<endl; func(a); cout<<"******************************"<<endl; return 0; }
相关文章推荐
- C++中explicit的作用
- C语言视频学习网站
- C语言基础—实现两个变量交换的三种方法
- fgetc
- C/C++ 操控访问SQLite3 数据库
- C++对C的增强
- C++基础编程----4.1表达式
- 线段树选讲
- 用c语言实现,两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同?
- C++从屏幕输入一行以空格分割的数字,存入整型数组
- Qt调用VC++生成的动态链接库
- C++设计模式 之 “单一职责”模式:Decorator、Bridge
- C++primer学习:拷贝控制(2)
- c语言学习笔记(14)指针基础
- 快速排序C++实现
- 关于C++中的模板和using namespace std 的冲突
- 设计模式学习笔记--原型模式
- C++ main函数传参
- 剑指offer第十六题【合并两个排序的链表】c++实现
- C++ 数组的指针,指针的数组, 数组引用