Question: Given the following segment of codes, please add a copy constructor in the derived class B and the base class A, and test it using
Given the following segment of codes, please add a copy constructor in the derived class B and the base class A, and test it using the main routine.
class A
{
int valuea;
public:
A() { }
int getValuea() const { return valuea; }
void setValuea (int x) { valuea = x; }
// copy constructor
};
class B : public A
{
int valueb;
public:
B() { }
int getValueb() const { return valueb; }
void setValueb (int x) { valueb = x; }
// copy constructor
};
int main ()
{
B b1;
b1.setValuea(5);
b1.setValueb(10);
B b2(b1);
cout << b2.valuea= << b2.getValuea() << b2.valueb= <<
b2.getValueb() << endl;
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
