I have the following two options for realizations of a class LargeInt that is supposed to hold unlimitted in size integers.
Option 1.
1 2 3 4 5 6 7 8 9 10 11
class LargeIntUnsigned
{
public:
unsignedint* Data;
unsignedint size;
};
class LargeInt : public LargeIntUnsigned
{
public:
signedchar sign;
};
Option 2. class LargeInt can also be realized as:
1 2 3 4 5 6
class LargeInt
{
public:
LargeIntUnsigned value;
signedchar sign;
};
Will the second realization consume more memory than the first?
In other words, will class LargeInt store a pointer to a separate object of type LargeInt? This means one extra pointer stored in memory, which I would like to aviod.
Another option is that class LargeInt "embeds" class LargeIntUnsigned (although it is not inheriting any of LargeIntUnsigned's methods).
Of course, the second realization is "morally" correct, since an signed integer is not "a kind of unsigned integer" which is the usual thing required when class B inherits class A.