I am confused, I hope somebody can clarify this for me - Thank You in advance.
ABSTRACT CLASS :
Let's assume I have a BASE ABSTRACT CLASS and two DERIVED CLASSES.
My BASE has a variable STRING NAME;
My DERIVED CLASSES have a variable STRING NAME.
When I set a value to my DERIVED CLASS variable - is that a separate variable?
I was thinking, I am just Defining the one variable in the base class accessed by the derived class,
but now I am thinking I am creating a whole separate variable in another class.
#include <iostream>
struct A
{
int x;
virtualvoid print() const
{
std::cout << "A: " << x << "\n";
}
};
struct B: public A
{
int x;
virtualvoid print() const
{
std::cout << "B: " << x << "\n";
A::print();
}
};
int main()
{
std::cout << "size of A = " << sizeof( A ) << "\n";
std::cout << "size of B = " << sizeof( B ) << "\n";
B b;
b.x = -7;
b.A::x = 12;
b.print();
}
[edit 2]
Sorry, one more thing. Neither A nor B above are abstract.
An abstract class is one that cannot* be instantiated (created as an actual object using actual memory) because some of its declared methods do not have defined bodies.
*should not
As always, things get a little murkier under the water, but this should do for now.