[問題] explicit instantiation的問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
MSVC14
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
原本的code是一個負責傳遞文字訊息class收到std::string或std::wstring之後
將文字訊息傳遞出去
所以在.h裡面宣告了
void send_message(const std::string& msg);
void send_message(const std::wstring& msg);
我想將這個function改寫成template 所以我寫了
template<typename T>
void send_message_t(const T&& msg);
在cpp裡做explicit instantiation
template void MyClass::send_message_t<std::string>(const std::string&&);
template void MyClass::send_message_t<std::wstring>(const std::wstring&&);
原有的function由於const char[]會implicit conversion成std::string所以當呼叫
send_message("message"); 的時候是沒有問題的
但是由於我做了explicit instantiation
目前只能寫成 send_message_t(std::string("message"));
我想我應該將const char[]也做explicit instantiation 可是不知道該怎麼寫..
有說錯的地方請指教 謝謝
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
cannot convert argument 1 from const char[8] to const char(&&)[8];
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.69.170.37
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1471314914.A.89B.html
推
08/16 11:05, , 1F
08/16 11:05, 1F
→
08/16 11:16, , 2F
08/16 11:16, 2F
→
08/16 11:27, , 3F
08/16 11:27, 3F
→
08/16 13:09, , 4F
08/16 13:09, 4F
→
08/16 13:46, , 5F
08/16 13:46, 5F
推
08/16 19:21, , 6F
08/16 19:21, 6F
→
08/16 20:04, , 7F
08/16 20:04, 7F
推
08/16 20:56, , 8F
08/16 20:56, 8F
→
08/17 10:39, , 9F
08/17 10:39, 9F
→
08/17 10:40, , 10F
08/17 10:40, 10F