#pragma, , ,
; ,
, , , , wierd
( ,
).
,
#pragma: g++ ; V++,
12 . ,
, private public, g++
V++, 8. ,
: int
,
Father, Father 8,
c. Child
( ) a int,
.
Child 12: 8 Father,
1 , 3 .
V++. ++
- " " (
,
): , , ,
. , Child
e Father + 5 (
Father), , ,
6 ( 8 ).
V++ , ;
. (
, .) g++
, , ,
, .
, , - :
Father* p1 = new Child;
Father* p2 = new Child;
memcpy( p2, p1, sizeof(Father) );
may have unexpected consequences, the size of the space actually occupied Father, may be less than sizeof
indicated. This may explain the g ++ choice logic: memcpynot valid if the class has private members, so they can apply it; this would be true if all the members (and several other conditions), so they do not apply it in order not to violate such things as above. (Adding a constructor that also makes it memcpyillegal calls g ++ to apply optimization.)