Class, default constructor ":"

Hey,

Can you guys explain me a little bit more the : after the default class constructor.
For example

1
2
3
4
5
6
7
8
9
class someClass{
private:
     float x, y;
public:
     someClass(float _x, float _y):
     x     (_x),     y     (_y)
     {};
     ~someClass(){};
};


Thanks in advance =]
It's class member initializer. It's used to assign value to variables in constructor.

someClass(float _x, float _y):x(_x),y(_y){};
is like,
1
2
3
4
someClass(float _x, float _y){
    x = _x;
    y = _y;
}
Last edited on
Thank you very much, lsk!=]
closed account (z05DSL3A)
Note: someClass(float _x, float _y) is not a default constructor.
A default constructor is one that takes no arguments.
Last edited on
Topic archived. No new replies allowed.