What topics does this cover in ?
Mar 2, 2019 at 1:19pm UTC
Hi. Im currently a student enrolling for object oriented programming c++. I have a code I couldn't solve. I tried inserting a few new method but also can seems to be getting it right
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <iostream>
using namespace std;
class myPointer {
private :
string label;
int *data;
void init (int sz,string lbl)
{
data = new int ;
*data = sz;
label = lbl;
}
public :
myPointer(){
init(2,"X" );
}
myPointer(int v,string lbl){
init (v,lbl);
}
void set(int v,string lbl){
*data = v;
label = lbl;
}
void print(){
cout << label << " = " << *data << endl;
}
};
int main(){
myPointer a;
a.set(68,"Z" );
myPointer b(a);
b.set(21,"W" );
a.print();
b.print();
return 0;
}
Mar 2, 2019 at 1:29pm UTC
Mar 2, 2019 at 3:51pm UTC
thank you for the links :D and also the solution
Topic archived. No new replies allowed.