constructor syntax ..?

what is this syntax signify ? Integer(long q = 0) : i(q) {} .. its a constructor for Integer class , with default value 0 .. but what does other half mean ie .. " : i(q)" ?
Constructor is like a function or method, but the name of constructor has name of the class and doesn't have return state. For example
1
2
3
4
5
6
class Test
{
public:
Test(){}       //constructor
void foo(){} //method
};

constructor can take params and maybe not. And constructor call automatically when you create a object.

In your example your are trying to init member variable of class Integer that has name 'i' by value that keeps in variable 'q'. When you will be situated in constructor scope member 'i' will be aleady inited.

Topic archived. No new replies allowed.