我需要我的異常類,繼承runtime_class
,接受wstring&
。這是MyExceptions.h
:string&vs. wstring&in runtime_error
using namespace std;
class myExceptions : public runtime_error
{
public:
myExceptions(const string &msg) : runtime_error(msg){};
~myExceptions() throw(){};
};
我想myExceptions
接受wstring&
這樣的:myExceptions(const **wstring** &msg)
。但是,當我跑,我得到這個錯誤:
C2664: 'std::runtime_error(const std__string &): cannot convert parameter 1 from 'const std::wstring' to 'const std::string &'
我明白runtime_error
接受string&
,而不是wstring&
定義爲從C++ Reference - runtime_error如下:
> explicit runtime_error (const string& what_arg);
我怎樣才能在runtime_error
使用wstring&
用?
如何編寫以wstring爲參數的另一個構造函數? – taocp
小的澄清:這是一個編譯錯誤,它恰好在錯誤消息中有運行時字樣。 –
我是這麼想的,但我不知道該怎麼做。我應該用這種方式覆蓋它?顯式的runtime_error(const wstring & msg);和在MyExceptions.h類的地方? – Colet