I am trying to add an additional argument into a constructor:
e.g. adding the argument 'y'
public Object(int x, int y) {
int x1;
int y1;
x1=x;
y1=y;
}
the original constructor was
public Object(int x) {
int x1;
int y1;
x1=x;
y1=(default number);
}
I know in Java, you could do something like this(x, 1)
to set y
to 1 if y is not given, but I think I read that constructors calling constructors doesn't work in C++?
Is there a way to initialize y
when it's not given, i.e. making sure that (1) and (2) both work?
Object o1 = new Object (5); // (1)
Object o2 = new Object (5,3); // (2)