【发布时间】:2015-04-22 19:33:48
【问题描述】:
我在VS2008上遇到了如下代码
if (!CreateProcess( NULL,
const_cast<LPWSTR>(ss.str().c_str()),
NULL,
NULL,
FALSE,
CREATE_NO_WINDOW|NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi))
{
throw std::exception("Unable to format Device");
}
现在我将代码移植到 mingw gcc 并收到错误
error: no matching function for call to 'std::exception::exception(const char [23])'
调查这个问题我注意到 Visual Studio 有一个文件异常,它确实有一个异常类并且确实接受了 char*。有些定义是这样的
__CLR_OR_THIS_CALL exception();
__CLR_OR_THIS_CALL exception(const char *const&);
__CLR_OR_THIS_CALL exception(const char *const&, int);
__CLR_OR_THIS_CALL exception(const exception&);
exception& __CLR_OR_THIS_CALL operator=(const exception&);
virtual __CLR_OR_THIS_CALL ~exception();
virtual const char * __CLR_OR_THIS_CALL what() const;
我的问题是我应该如何在 mingw gcc 上规避这个构建问题?我应该创建一个继承自 std::runtime_error 的新类并抛出它吗?
【问题讨论】:
-
std::exception::exception(const char*)不是 c++ 标准,而是 MS 特定的实现 en.cppreference.com/w/cpp/error/exception/exception
标签: c++ visual-studio c++11 gcc