Home > Back-end >  How to solve these two problem duck
How to solve these two problem duck

Time:09-18

1. Read the following program, complete the copy constructor code,

#include using namespace std;
Class CAT {public: (CAT);
The CAT (const CAT&); ~ (CAT);
Const int GetAge () {return * itsAge; }
Void SetAge (int age) {* itsAge=age; } protected: int * itsAge; }; CAT: CAT ()
{itsAge=new int. * itsAge=5; }
CAT: CAT (const CAT& C)
{___. ___. }
CAT: : ~ (CAT) {delete itsAge; }




2. The output of the following procedure is known: 10

Please make up Sample class member functions, don't add member variable,

#include using namespace std; The class Sample {public: int v; The Sample (int n) : v (n) {}
//add code here
___}; Int main () {Sample a, (5). The Sample b=a; Cout & lt;






CodePudding user response:

1//copy constructor, give a member variable application memory and assignment
ItsAge=new int. * be sad etAge chtistina georgina rossetti.british poetess itsAge=();

2//copy constructor, the member variable * 2
The Sample (const Sample & amp; A) {this - & gt; V=2 * Dr.); }
  • Related