class - The rule of The Big Three -


iam confused below question did program per understanding crashes doing wrong? if can please assist me appreciated.

my main.cpp looks this:

    #include <iostream>     #include <iomanip>     #include "number.h"      using namespace std;      int main()     {         number n1(10);         number n2 = n1;         n2.printnum();         n2.addone();         n1 = n2;         n1.printnum();          return 0;     } 

then header file looks this:

    #include <iostream>     using namespace std;      class number     {         int *p;         public:             number(int);             void addone();             void printnum();     }; 

and below parts constructor need complete there shows comments that's part should complete:

    #include <iostream>     #include "number.h"      using namespace std;      number::number(int a1)     {         *p = a1;//write code needed initialise value of   member variable a1     }     void number::printnum()     {     cout << "the number " << *p << endl;     }     void number::addone()     {         *p++;//write code needed increment value of member variable one.     } 

then question asks below should code use big three?

consider following program. complete class definition (where asked to) , check output. can see that program works without error once completed. however, experts suggest in class uses pointers , new operator better follow rule of big three. modify class definition follow rule of big 3 , submit new program , output. demonstrate use of pointer.

thank rohan


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -