Strange class statement...
While I was looking at an example of class operations I saw something I never seen before. Where the constructor for class Position is declared there is a :x(xx),y(yy) statement and I cant understand what it is doing. I seems like it is using float x and y as functions, and this even before the {}. Please explain this statement, what it does, how it does it, what else strange statements like this you can do and if there is any where I can read more about this?
Code:
#include<iostream.h>
class Position {
float x,y;
public:
Position(float xx, float yy=0):x(xx),y(yy) {}
Position operator + (const Position& e) const;
Position operator - (const Position& e) const;
void Display(void)
{ cout << "(" << x << ", " << y << ")" << endl; }
void Input(void)
{ cout << "enter x och y:"; cin >> y;; }
};
Position Position::operator + (const Position& e) const
{
Position res = *this;
res.x += e.x;
res.y += e.y;
return (res);
}
Position Position::operator - (const Position& e) const
{
Position res = *this;
res.x -= e.x;
res.y -= e.y;
return (res);
}