So in C++, you can have a reference (auto-resolved pointer) as a member of your class, if you initialize that member in the constructor with a like reference. That way you can have several objects that refer to the same thing, with no null pointer problems.
Then you try to inherit from that class with a class that includes an object of that type, not a reference. Easy, just pass a reference to the object to the base class constructor. That way you can have objects like the first, but they all refer to their own thing, with no code duplication.
Except it won't initialize the object until B's constructor is complete.
B::B(A& thingy): myreference(thingy) {
// boy I hope thingy isn't uninitialized data!
performSurgery(thingy.foo);
}
To solve this, you can't. There's no way to do it, and no one can ever write a program in C++ that does.
#C++
#programming #FuckEverything #opinions #ProveMeWrong