So I've started dabbling around a bit with base classes and derived classes, however, now that I'm getting into it seems that I've hit a wall. Basically, what I am want to do is assign an already initialized base class to a derived class. Reason for this being is that I'd like to access some variables of said base class in functions of my derived class.
I've came up with the following method of doing this:
class Bar
{
public:
int Example = 16;
};
class Foo : public Bar
{
public:
Bar* BarInstance;
Foo(Bar* ClassInstance) : BarInstance(ClassInstance)
{
}
int GetExample()
{
return BarInstance->Example; // Seems to work fine
}
};
This seems to work fine, however I'd like to make this easier and just access it like this:
Foo* FooInstance = new Foo(this) // Where this is an instance of bar
int Output = FooInstance->Example; // Expected output is 16 (see above snippet of code)
Is this possible? I remember reading about a problem similar to this one, unfortunately I was not able to find it again. Any help is appreciated!