A *ptr; B b(30,50); ptr=&b;
#include <stdafx.h> #include <iostream> #include <fstream> #include <assert.h> #include <cassert> // for assert() using namespace std; class A { public: int a; A(int t) { a=t; } void Fun_A() { cout<<"Class A Fun()"<<a; } }; class B: protected A // Private mode has the same problem But in public mode it is ok { public: int b; B(int t,int x):b(t),A(x) { } }; void main(void) { A *ptr; B b(30,50); ptr=&b; }
A *ptr; B *b(30,50); ptr=(A*)b;
class B: protected A // Private mode has the same problem But in public mode it is ok { public: A* operator & (){ return this; } // other members };
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)