Daily Archives: October 27, 2021

return 0 for std::string type

看到一段有問題的code,簡化如下 這樣子會compile過嗎? 答案是可以,此範例是可以通過compile。但是0是integer,integer和string應該不相容吧? 的確是不相容,其他的integer會compile不過,剛好 0 例外,在 C++11 4.10描述了 null pointer constant可以被轉成 null pointer 答案是可以,原因就在 std::string 接收 implicit construct from char pointer A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or … Continue reading

Posted in C++ Language | Leave a comment