复制构造函数
//复制构造函数 #include "stdafx.h" #include <iostream> using namespace std; class CPen { private: int m_size; public: CPen(int size); CPen(CPen &pen); int GetSize(); void Write(); }; CPen::CPen(int size) { m_size = size; } CPen::CPen(CPen &pen) { m_size = pen.GetSize(); cout << "size and long" << endl; } int CPen::GetSize() { return m_size; } void CPen::Write() { cout << "the value of m_size if:" << GetSize() << endl; } int main(int argc, char* argv[]) { //printf("Hello World!\n"); CPen pen1(10); pen1.Write(); CPen pen2(pen1); pen2.Write(); return 0; }
学习笔记转摘于:
丝酷网 http://www.pythonschool.com/