How should I get rid of the problem with object slicing in c++.
In my application if the derived class has some dynamically allocated pointer and derived class object is assigned to base class object, the behavior is memory corruption!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on your design. You may have to change certain design criteria to get rid of it. One of the options is to have an overloaded
operator =and copy constructor in your baseclassfor particular derivedclass.Now if you attempt to do something like following:
it will result in compiler error.