2010.4.4学习笔记
来源:互联网 发布:淘宝重复铺货 编辑:程序博客网 时间:2024/06/16 00:45
1.构造函数、析构函数、拷贝构造函数
其中copy constructor有三种情况:
(1)If an object is initialized by another object of the same class, the copy constructor is invoked automatically.
B=A;
B(A);
(2) If the arguments of the function is an object of a class, the copy constructor is invoked when the function is invoked.
eg:void fun1(Point p){
cout<<p.GetX()<<endl;
}
void main(){
Point A(1,2);
fun1(A); // copy constructor is invoked
}
(3)If the function returns an object of a class, the copy constructor is invoked.
eg: Point fun2(){
Point A(1,2);
return A; //copy constructor is invoked
}
void main(){
Point B;
B=fun2();
}
深拷贝和浅拷贝:
string s1("hello"),s2;
s2=s1;
浅拷贝:指针s1,s2指向了同一段内存。
Default copy constructor.
Only copy the address of the resource
深拷贝:为被赋值的对象新开辟了一段内存。
User-defined copy constructor
Can copy the resource
2 explicit 关键字
This keyword is a declaration specifier that can only be applied to in-class constructor declarations. An explicit constructor cannot take part in implicit conversions. It can only be used to explicitly construct an object.
首先explicit只能在类内部的构造函数中使用
如果被声明为explicit,那么只能显示的调用构造函数。
A(1,2);
不能隐式转换来调用构造函数.
B=A;
反义词(implicit,隐晦的,含蓄的)
- 2010.4.4学习笔记
- C++学习笔记(4)
- AD学习笔记4
- oracel学习笔记4
- JavaScript学习笔记4
- JavaScript 学习笔记 4
- EJB学习笔记(4)
- Solaris学习笔记(4)
- Java学习笔记4
- c#学习笔记4
- LSL学习笔记(4)
- stl学习笔记4
- JavaScript学习笔记4
- ASP+ 学习笔记 4
- HTML学习笔记(4)
- jsp学习笔记4
- java学习笔记4
- java学习笔记4
- 关于如何在MyEclipse 7.0上连接SQL2005驱动的总结
- 认识任务管理器
- D-Bus学习(五):Signal的收发小例子
- Windows Server 2003 负载均衡
- (转)Offshore时代的统筹人---7
- 2010.4.4学习笔记
- Struts2小结
- LR语法分析-简单的LR技术
- 单词
- 何为抓住机遇,何谓现实社会
- 临时性道指令程序测试
- 感染ELF文件(2)
- SPL - QQ空间日志查看工具 v1.1.0.441
- 心烦