我是C ++编程的新手。这是Bjarne Stroustrup的C ++书中的一个示例。 谁能告诉我这行的意思
X(int i =0) :m{i} { } //a constructor ( initialize the data member m )
谁能告诉我这个':
'符号的作用。我是c ++程序的新手。
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
}