#include <iostream>

class Example {
    private:
        int a;
        // lots of important variables that live on the heap
    public:
        int getA() { return a; }
        
        Example(Example& other) {
        	std::cout << "Example copy constructor" << std::endl;
        	a = other.a;
        }
        
        Example(int a_local) {
            a = a_local;
            std::cout << "Example constructor" << std::endl;
            /* allocating memory, etc. ... */
        }
};

class Child: public Example {
    // we get `a` and `getA()` from example
    private:
        int b;
    public:
    	Child(int a2, int b2) : Example(a2) {
    		std::cout << "Child constructor" << std::endl;
    		b = b2;
    	}
    
        int getB() { return b; }
        int getAplusB() { return getA() + b; } // we can't use `a` directly since it's private
};

int main() {
	Child c(1, 5);
	std::cout << c.getA() << std::endl;
	std::cout << c.getB() << std::endl;
	std::cout << c.getAplusB() << "\n" << std::endl;
	
	Example& e = dynamic_cast<Example&>(c);
	// Example& e = c;
	// Example e = c;
	std::cout << e.getA() << "\n" << std::endl;
	
	// Example e2(10);
	// Child c2 = dynamic_cast<Child&>(e2);
}