I am new to c++ programing.This is an example in Bjarne Stroustrup's c++ book. Can any one explain to me what this line does
X(int i =0) :m{i} { } //a constructor ( initialize the data member m )
Can anyone tell me what does this ':
' symbol does.I am new to c++ programs.
class X {
private: //the representation (implementation) is private
int m;
public: //the user interface is public
X(int i =0) :m{i} { } //a constructor ( initialize the data memberm )
int mf(int i) //a member function
{
int old = m;
m = i; // set new value
return old; // return the old value
}
};
X var {7}; // a variable of type X initialized to 7
int user(X var, X∗ ptr) {
int x = var.mf(7); // access using . (dot)
int y = ptr−>mf(9); // access using -> (arrow)
int z = var.m; //error : cannot access private member
}