A simple question, I want to initialize my variables in a class using a constructor. the data will be taken from the user, stored in local variable in MAIN and it should be passed to constructor, by when doing it in action, its wrong, is there any special form here for giving argument to the constructor?
I did, ok mikey let me write you part of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class mikey{
public:
mikey(int x, int y){x1=x; y1=y;}
private:
int x1, int y1;
}
int main()
{
int M_x, M_y;
cin>>M_x;
cin>>M_y;
mikey m1(M_x, M_y);
}
it does not work cause i have declared two argument of type int to be passed to the argument, so my question is how the variable values in main should be passed now to the constructor?
NwN, thanks for your reply, because when i run the code, compiler returns an error stating that this function has not been declared, but when i replace those variables with actual integers there will be no problem.