Home > Back-end >  Bosses, help, that which is wrong
Bosses, help, that which is wrong

Time:03-19

# include

using namespace std;

The class MyClass

{

Public:

MyClass () {x=0; y=0; }

MyClass (int a=0, b=0).

Print ();

Private:

Int x, y;

};

MyClass: : MyClass (int a=0, int b=0)

{

X=a;

Y=b;

}

Void MyClass: : Print ()

{

Cout & lt; <"X=" & lt;
Cout & lt; <"Y=" & lt;
}

Int main ()

{

MyClass obj1 obj2 (5, 8);

Obj1. X=1;

Obj1. Y=3;

Obj1. Print ();

Obj2. Print ();

return 0;

}

CodePudding user response:

Reference:
 # include 

using namespace std;

The class MyClass

{

Public:

//MyClass {x=0; y=0; }

MyClass (int a=0, int b=0).

Void set_var (int x, int y);

Void Print_m ();

Private:

Int x, y;

};

MyClass: : MyClass (int a, int b)

{

This - & gt; X=a;

This - & gt; Y=b;

}

Void MyClass: : set_var (int x, int y)
{
This - & gt; X=x;
This - & gt; Y=y;
}

Void MyClass: : Print_m ()
{
Cout & lt; <"X=" & lt;
Cout & lt; <"Y=" & lt; }

Int main ()

{

MyClass obj1 obj2 (5, 8);

Obj1. Set_var (1, 3);

//obj1. X=1;

//obj1. Y=3;

Obj1. Print_m ();

Obj2. Print_m ();

return 0;

}