std::runtime_error:runtime_error(const string& arg)
에 대한 자체 정의가 필요합니다. 우리는 같은, 즉, 다른 생성자의 관점에서 std::runtime_error:runtime_error(const char*)
을 같은 생성자를 구현 : 생성자 std::runtime_error::runtime_error(const string& arg)
이 존재하지 않기 때문에 GCC-4.9.1와gcc 4.9.1 표준을 준수하지 않습니까? (std :: runtime_error)
namespace std {
runtime_error::runtime_error(const string& arg)
: runtime_error(arg.c_str()) {
...
}
}
, 이것은 불가능하다. GCC에서/4.9.1// C++/4.9.1/stdexcept에게을 포함, 우리는 다음을 참조하십시오
...
class runtime_error : public exception
{
string _M_msg;
public:
/** Takes a character string describing the error. */
explicit
runtime_error(const string& __arg);
virtual ~runtime_error() _GLIBCXX_USE_NOEXCEPT;
/** Returns a C-style character string describing the general cause of
* the current error (the same string passed to the ctor). */
virtual const char*
what() const _GLIBCXX_USE_NOEXCEPT;
};
...
기준은 명확하게 명시 runtime_error(const char*)
생성자가되어야한다고 말한다.
19.2.6 클래스 runtime_error는 [runtime.error]
namespace std {
class runtime_error : public exception {
public:
explicit runtime_error(const string& what_arg);
explicit runtime_error(const char* what_arg);
};
"* 우리는 다른 생성자에 대해 이러한 생성자를 구현합니다. *"왜 그러고 싶니? 'std :: string'을 취하는 것은 길이를 가지고 있고, 다른 것은 길이를 계산하기 위해'strlen'을해야합니다. 그것은 단지 시간 낭비 일뿐입니다. 또한 표준 라이브러리에서 클래스를 다시 작성할 수 없습니다. –
'-std = C++ 11'을 사용하고 있습니까? –
@FredLarson 기본값이어야합니다. –