protected, . test, A B . a static_cast , reinterpret_cast reinterpret_cast. B , , B . :
struct B : protected A {
A* get() { return this; }
void print() { cout << i << endl; }
static B* cast_to_b(A* io_self) { return static_cast<B*>(io_self); }
};
extern "C" {
void test(A* io_self) {
auto b2 = B::cast_to_b(io_self);
b2->print();
}
}
, , A* io_self, B, a A undefined.
, protected ? , private , , , B. B a A.