您的位置:首页 > 移动开发 > Objective-C

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: