Re: [問題] G++ and VC++ Constructor 問題
※ 引述《ROGZ (ROGZ)》之銘言:
這種問題多半是不同STL版本問題
我個人對於這疑問的建議是,直接翻STL Source code。
翻STL這件事情沒那麼可怕,而且很多IDE都可以快速的幫你找到位置
比方說你的問題,大多數合格的IDE瞬間理解string要找到這裡 :
template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
{
_LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
__init(__s, traits_type::length(__s));
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
也就是說其實他會對value_type去取長度(用traits_type::length)
這部分就先解決了你的問題:他怎麼知道const char*長度的
至於basic_string是什麼?string是basic_string的一個特殊具現化
但是你其實先不用知道,IDE都會幫你先處理掉
至於為什麼VC不行,我個人手邊是沒有windows不知道他STL怎麼實作的
不過你可以依樣畫狐狸的找一下能不能找到source code來討論?
以及你VC版本,以及他出了什麼error message?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.177.112.114
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1496324660.A.5D3.html
推
06/01 22:02, , 1F
06/01 22:02, 1F
→
06/01 22:03, , 2F
06/01 22:03, 2F
→
06/01 22:53, , 3F
06/01 22:53, 3F
→
06/01 22:53, , 4F
06/01 22:53, 4F
推
06/01 22:54, , 5F
06/01 22:54, 5F
→
06/01 22:54, , 6F
06/01 22:54, 6F
→
06/01 22:55, , 7F
06/01 22:55, 7F
→
06/01 23:22, , 8F
06/01 23:22, 8F
→
06/01 23:22, , 9F
06/01 23:22, 9F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 3 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章