Overloading STD :: Whow()无法转换const char*
overloading std::what() cannot convert const char*
我正在写我的异常类:
class MyExcept: public std::exception
{
public:
MyExcept(std::string _msg);
virtual ~MyExcept() throw();
virtual const char* what() const throw();
private:
std::string m_errorMsg;
};
MyExcept::MyExcept(std::string _msg)
: m_errorMsg(_msg)
{
}
MyExcept::~MyExcept() throw()
{
}
const char* MyExcept:: what() const throw()
{
return m_errorMsg.c_str;
}
i用G 编译,并在函数中获取返回行的以下错误():
无法转换'std :: __ cxx11 :: basic_string< _ chart,_traits,_alloc> :: c_str,std,std :: allocator>'type'const char*(std :: __ __ __ cxx11 :: basic_ basic__basic__string ::::: ::)const ::)'键入'const char*' 返回m_errormsg.c_str;
我做错了什么?谢谢
使用 return m_errorMsg.c_str();
,它应该工作- c_str
是a function ,而不是 actibal 。。
相关文章:
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 'HMODULE LoadLibraryA(LPCSTR)':无法将参数 1 从 'const _Elem *' 转换为 'LPCSTR'
- 将函数参数"const char*"转换为"std::string_view"是
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 启用从"vector<const T>&"到"const vector&"的隐式转换<T>
- 将 const 转换为 const char* 无效,我该如何解决?使用 gcc7 时失败
- C++ TCP 套接字 | 无法将"std::__cxx11::字符串"转换为"const
- C++ 无法从 const int* 转换为 const_iterator
- 为什么我的编译器在调用 const getter 函数时抛出"转换丢失(const)限定符"错误?
- 如何在 c++ 中将向量转换为<string>常量字符* const*?
- 无法从'const std::string [3]'转换为'std::string'
- 无法在返回中转换 const 对象
- Tensorflow Lite ARM64错误:无法转换‘const int8x8_t
- 一种体面的方式来转换const列表参考参数,然后传递到另一个函数
- Overloading STD :: Whow()无法转换const char*
- 使用工厂方法时编译器错误:无法转换"const std::p air<char* const
- 强制转换 const 指针以使用旧版 C 代码
- 使用地址解释强制转换const
- c++转换const引用传递
- c#可以强制转换const吗?