So I'm working on one problem where it's my job to add some features to a C++ implementation of battleships. All's fine and dandy but I encountered something like this in a constructor for a ship of size two:
class PatrolBoat : public Ship {
private:
int x, y;
char deck[2];
public:
PatrolBoat(int x, int y) : x(x), y(y) {
deck[0] = '_';
deck[1] = '_';
}
virtual void draw(int x, int y){
cout << deck[y - this->y];
}
virtual void shoot(int x, int y){
deck[y - this->y] = 'T';
}
};
I understand the first colon - it just inherits from its parent, the Ship class. But what about the part with the constructor: PatrolBoat(int x, int y) : x(x), y(y) {
? What does the x(x) and y(y) mean? I can't make sense out of it and couldn't google my way out of the impasse. Could you please help?