(C/C++学习笔记)Copy构造函数应用场景
2015-08-07 09:55
369 查看
Copy构造函数应用场景
#include"iostream" using namespace std; class Location { private: int X,Y; public: Location(int xx = 0 , int yy = 0) { X = xx; Y = yy; cout << "Constructor Object . \n"; } Location(const Location &p) { X = p.x; Y = p.y; cout << "Copy_constructor called ."<< endl; } ~Location() { cout << X << "," << Y << " Object destroyed. "<< endl; } int GetX() { return X; } int GetY() { return Y; } }; void f (Location p) { cout << "Function:" << p.Getx() << "," << p.GetY() << endl; } void playobjmain() { Location A(1,2); f(A); } int main(int argc, char const *argv[]) { playobjmain(); return 0; }
相关文章推荐
- C++ 头文件重复包含
- C/C++获取当前系统时间
- C语言基础、技巧_自总结版
- C++ Hello World
- C语言的关系运算符
- 链表排序(C语言)选择排序
- C++ Primer Plus第六版 第九章 编程练习答案
- C/C++知识要点4——printf函数以及cout的计算顺序
- c++学习笔记1
- c++ list iterator not incrementable
- C/C++知识要点3——类成员函数的重载、覆盖和隐藏的区别
- C++中的string类的用法小结
- qdbuscpp2xml工具用法中输入和输入
- 求最大连续子向量之和
- C++_避免调用复制构造函数
- C语言 内存泄露(只对XP有效果)
- 重温C++之“strcpy_s与strcpy的比较”
- 重温C++之“字符类型总结区别wchar_t,char,WCHAR”
- C++ Virtual详解
- C++中friend的使用(friend function and friend class)