小编hum*_*odz的帖子

std::runtime_error 中的显式构造函数

根据 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 字符串的转换吗?

c++ constructor explicit

1
推荐指数
1
解决办法
537
查看次数

标签 统计

c++ ×1

constructor ×1

explicit ×1