来自13节,关于初始化顺序
class Wacko {
public:
Wacko(const char *s): s1(s), s2(0) {}
Wacko(const Wacko& rhs): s2(rhs.s1), s1(0) {}
private:
string s1, s2;
};
Wacko w1 = "Hello world!";
Wacko w2 = w1;
这个程序理论上的结果是不是
w1:s1="hello world", s2=0
w2:s1=0,s2="hello world"
我运行这个程序就出错,不知道为啥,
出错信息:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
请高人指点下这个程序以及内部潜在的问题,谢谢。!