Accelerate C++ Chapter01
Exercises
Exercise 1-1
Are the following definitions valid? Why or why not?
const std::string hello = "Hello";
const std::string message = hello + ", world" + "!";
编译正确。std::string 重写了 + 操作符
Exercise 1-2
Are the following definitions valid? Why or why not?
const std::string exclam = "!";
const std::string message = "Hello" + ", world" + exclam;
编译报错。因为 “Hello” 为 const char *,并没有重载操作符,所以编译报错。