根据 cplusplus.com,这是 std::runtime_error 类的实现:
class runtime_error : public exception {
public:
explicit runtime_error (const string& what_arg);
};Run Code Online (Sandbox Code Playgroud)
由于构造函数是显式的,我希望它只接受 std::string 对象。
throw std::runtime_error("error message");Run Code Online (Sandbox Code Playgroud)
但是,此代码编译(GCC)。编译器不应该抱怨隐式 const char* 到 const 字符串的转换吗?