おそらく、この質問に答えるGoogleの検索がありますが、私の人生では何百万という無関係な答えを得られないものは考えられません。
そう、
In MSVC text inside quotes "like this" is taken, I think, as a std::string or, maybe, std::string&. In g++/gcc it always seems to be taken as const char*. True?
私が試してみたいコードスニペットが見つかりました。
if(NULL == key)
throw exception("Empty key");
MSVC/VC ++でうまくコンパイルする(2008年(ただし、g ++(4.4.3)で試してみると
no matching functions for calls to std::exception::exception(const char&)
私はこれを働かせる:
if (NULL == key)
{
std::string estr ("Empty key");
throw exception("Empty key");
}
しかし、それはちょうど醜いです。
これは私に別のエラーをもたらした:
std::string estr ("");
if (NULL == key)
{
estr = "Empty key";
throw exception("Empty key");
}
I have no clue what exception() expects as its input. I did find something that suggested std::string or maybe std::string& but I lost that page and the millions of unhelpful pages I've found since are, well, useless. Have all kinds of info on exception class, exception use,....
Short of my ugly fix, is there a simple way to tell g++ that "this is a std::string" not a const char& and still keep VC++ happy? (obviously I'm trying to do cross compilable code from single source.)
そしてそのことについては、どのようにID
throw exception("Empty key");
と違う
throw "Empty key";
ありがとう、
ウェス