- #include <iostream>
- struct A {
- int foo;
- A() : foo(3) {}
- };
- struct B {
- int bar;
- B() : bar(4) {}
- };
- struct C : public A, public B {
- };
- int main() {
- const C* c = new C();
- // Cast away const, and also convert to base class B.
- B* b = (B*)c;
- std::cout << "bar = " << b->bar << std::endl;
- delete c;
- return 0;
- }