, ABI. , , .
POD ++ 11.
++ 11 . , , " " pod.
( ).
, .
, , .
template<class T>
struct value_ptr {
T* raw;
};
->clone() , , , ( ) ( unique_ptr ). unique_ptr, ->clone(). unique_ptr , .
. -, ( T* clone() const), - :
struct my_regular_foo {
value_ptr< IFoo > ptr;
bool some_method() const { return ptr->some_method(); }
};
: , , , . , , .
, .
IFoo . IFoo ( ABI (!) - ), my_regular_foo, . my_regular_foo, , , - - , , , , , , , ( ).
: IFoo ( : ), virtual , , virtual API ( , vtable vtable : - vtable . vtable , , ).
This last step - using new methods on your interfaces - can be a bridge away, since you have to explore the ABI guarantees (in practice and not) on the vtable layout for each supported compiler.
source
share