a.empty() ? a : (b.empty() ? b : c) 超级奇怪问题.
代码 1:
#include <iostream>#include <string>using namespace std;int main(){ string a, b, c; a.empty() ? a : (b.empty() ? b : c) = "fkdlsajfa"; // a, b, c 都没有被赋值. 何解? cout <<a <<endl <<b <<endl <<c <<endl; return 0;}#include <iostream>#include <string>using namespace std;int main(){ string a("a"), b("b"), c("c"); a.empty() ? a : (b.empty() ? b : c) = "fkdlsajfa"; // c 被赋值. cout <<a <<endl <<b <<endl <<c <<endl; return 0;}