Results 1 to 2 of 2

Thread: Can we use derived class pointer

  1. #1
    Junior Member
    Join Date
    Feb 2007

    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?

  2. #2
    Junior Member
    Join Date
    Mar 2010

    Re: Can we use derived class pointer


    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
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.