Write a short program that shows how to defeat the slicing problem.
What will be an ideal response?
```
// to defeat the slicing
problem#include
B():bPtr(new char('B')){ }
virtual void f(){ cout << "B::f() " << *bPtr <<
endl; }
virtual ~B(){ delete[] bPtr; }
private:
char * bPtr;
};
class D:public B
{
public:
D():B(),dPtr(new char('D')){ }
void f(){ cout << "D::f() " << *dPtr << endl; }
~D() { delete dPtr; }
private:
char * dPtr;
};
int main()
{
B *b1;
B *b = new B;
D *d = new D;
d->f(); // calls D::f()
```
You might also like to view...
Some companies offer health and wellness programs that require employee participants to share personal data. This data is protected under the same HIPAA privacy regulations as data shared with health insurance companies and doctors.?
Answer the following statement true (T) or false (F)
Choose the correct verb to agree in number with the subject of the following sentence. Each of these salad dressings __________ low in calories.?
A. ?is B. ?are