-
Junior Member
Can we use derived class pointer
While using virtual function, usually we use base class pointer to access derived class object. can we use derived class pointer to access base class object. if no, what is the reason?
-
Junior Member
Re: Can we use derived class pointer
Hi,
There is nothing wrong in doing it the way you said...You won't even get any compile or run-time error. But the problem is you won't get the output that you have anticipated because "object slicing" occurs whenever you perform "downcasting"( referring to the base class thru a derived class). Because construction of an object always occurs from "top down" in a hierarchy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules