类的赋值初始化
2015-09-27 21:08
267 查看
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <iostream> #include <vector> #include <string> #include <stack> using namespace std; class base { public: base() { cout << "*" << endl; } base(int n) { id_ = n; } base(const base& t) { id_ = t.id_; cout << "***" <<endl; } base& operator=(const base& t) { id_ = t.id_; cout << "**" << endl; return *this; } private: int id_; }; int main(int argc, char* argv[]) { base a(3); base b = a;//赋值初始化调用的是拷贝构造函数 return 0; }输出:“***”
相关文章推荐
- 带表头结点的单链表HeaderList
- tomcatport占用,如何识别和kill
- WebView(网络视图)
- 王思聪投资的这个17为什么能登顶AppStore
- java SE复习笔记44
- 使用URL读取网页的内容
- Swift的初始化方法
- css 2D和3D的运用
- Eclipse-Mars Release (4.5.0)创建Maven项目报错
- 经常让写的关于链表的代码
- 第一篇博客
- java SE复习笔记43
- 《软工视频之微观了解一》
- Smallest unused ID
- 《Python网络编程基础》第四章 域名系统
- C#控制台程序取得INSOYA视频区的视频的真实URL,视频标题,发布时间集合。
- 鸟哥学习笔记
- java SE复习笔记42
- 网络知识小笔记
- 心得