我的问题是基于句子的效果,void print(const string& msg = "")
如果与,有什么区别void print(const string& msg)
,
当我在中使用打印函数时main()
,我可以在不传递函数参数的情况下调用该函数print()
吗?喜欢p.print()
?
class Point {
int i, j, k;
public:
Point(): i(0), j(0), k(0) {}
Point(int ii, int jj, int kk)
: i(ii), j(jj), k(kk) {}
void print(const string& msg = "") const {
if(msg.size() != 0) cout << msg << endl;
cout << "i = " << i << ", "
<< "j = " << j << ", "
<< "k = " << k << endl;
}
};
int main() {
Point p, q(1,2,3);
p.print("value of p");
q.print("value of q");
} ///:~