class object assign operater
2008-03-24 17:31
323 查看
class A {
...
} // declaration A
A a1;
A a2;
a1.foo();
a1.variable = ...
a2 = a1;
What value should a2 has ?
case 1: no override on operater=
there should be a memory copy from a1 to a2; such as
memcpy(&a2, &a1, sizeof(a1)); so if there is pointer type member in class A, both a1 and a2 will have a pointer which is point to same object.
case 2: override the operator=
the operator= will be called instead.
...
} // declaration A
A a1;
A a2;
a1.foo();
a1.variable = ...
a2 = a1;
What value should a2 has ?
case 1: no override on operater=
there should be a memory copy from a1 to a2; such as
memcpy(&a2, &a1, sizeof(a1)); so if there is pointer type member in class A, both a1 and a2 will have a pointer which is point to same object.
case 2: override the operator=
the operator= will be called instead.
相关文章推荐
- DataTable操作
- StringTokenizer类的使用方法
- 反射技术动态调用方法中的引用类型参数传递 (转)
- .NET中如何在调用COM的时候得到返回参数值 (转)
- 关于rootkit和anti-rootkit的一些思考(2)
- 多线程调用DataGridView
- 业务实体对象(Business Entity Object)的序列化
- Object-Oriented设计
- Flash OBJECT和EMBED标签
- Flash OBJECT和EMBED标签
- 筛选王 for Economist.com
- 自定义动画效果(Iris动画修改)
- ObjectType HOOK干涉注册表操作
- virtual function的一些心得
- Manning. JUnit in Action 文摘-1
- WaitForSingleObject
- 在firefox下调用flash对象的方法不成功的解决办法
- WaitForSingleObject的用法
- 转: Hibernate查询解决方案
- GridView RadioButton 样板列