Hi there,
I am currently working on classes and constructors. I have just worked on standard constructors and simple parameter constructors, and since I have been playing around with Java a bit in the past, a question came to my mind.
My textbook uses a class "Place" with two integer coordinates as members as an example, and so far I have been writing two constructors:
Code:
class Place {
public:
Place();
Place(int x, int y);
...
private:
int xCoord;
int yCoord;
}
Code:
Place::Place() {
xCoord = 0;
yCoord = 0;
}
Place::Place(int x, int y) {
xCoord = x;
yCoord = y;
}
Now my question is, in Java it is common practice and also considered good practice to redirect constructors. In C++, is there any disadvantage with this:
Code:
Place::Place() {
Place(0, 0);
}
Place::Place(int x, int y) {
xCoord = x;
yCoord = y;
}
Under the hood, does this piece of code the same as the above? Is it considered good or bad practice? Is it something common in C++?