I'm new to C++, and I had a question about constructors. Say, for example, I'm writing a class for a 2D vector. I want my constructor to take an x
coordinate and a y
coordinate. The issue is that I also have fields called x
and y
to store the coordinates.
If I'm writing this constructor in Java, for example, I would write:
public class TwoDVector {
int x;
int y;
public TwoDVector(int x, int y) {
this.x = x;
this.y = y;
}
}
Now, say I wanted to do something similar in C++. C++ doesn't seem to have a this
keyword that works the same way as Java's, so would the only course of action be renaming the parameters? Thank you so much for your help!