class A
{
public:
int a;
A() : a(100) { }
};
class B : public A
{
public:
int b;
B() : b(200){ }
};
int main()
{
A a;
B *ptrB =(B*)&a;
cout<<ptrB->b<<endl; // Is there a way to get this to print 200??
}
ahtaniv
0
Newbie Poster
Recommended Answers
Jump to Postthe pointer is pointing to an object of class A which has no relation with class B...
using base class object cannot print value of b.
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.