C++中操作符与构造函数的调用

a. string x; // 调用default constructor

b. string x = 10; // 调用constructor parameterized by int,这条语句相当于string x(10);

c. string x = "abc"; // 调用constructor parameterized by const char *,这条语句相当于string x("abc");

d. x = "xyz"; // 调用assign operator

e. string c = a + b; // 先调用add operator,再调用default constructor

f. string c = a + "abc"; //先调用constructor parameterized by const char *构造出一个string,再调用add operator, 最后调用default constructor

注意,<<>>操作符的重载要声明在类定义的外面,其他的声明在里面。

posted on 2011-09-01 11:45  chihits  阅读(193)  评论(0编辑  收藏  举报

导航