When using wrapper classes in C++, like
class myInt {
int _value;
public:
myInt( int value ) : _value( value );
int value() const { return _value; }
}
, is there any memory overhead compared to a simple int?
This answer says "not if there's no virtual functions", but I want to understand the exact reason.
I looked into § 10.3 [class.virtual] of ISO/IEC 14882:2003, which say: "A class that declares or inherits a virtual function is called a polymorphic class." I understand that objects of such a class do not need to have a vtable pointer in them.
But I don't understand how it follows from this that it does not have to have any memory overhead. I can create a class deriving from myInt, calling it, say, myDerivedInt. Can't I do a dynamic_cast from a myInt * to a myDerivedInt *? If not, why not?