[問題] 有關C++Primer中文版,p461頁(12.4.4節)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
none
問題(Question):
C++ Primer (4ed) p461
12.4.4 真的很奇怪;看了幾次不能推敲出它的意思
所以想上網問一下專家
以下是我盡量湊成的程式碼(我想先嘗試沒有explicit關鍵字的情形)
#include <string>
#include <iostream>
using namespace std;
class Sales_item
{
private:
string data; //放isbn字串
public:
Sales_item(const string& book);
Sales_item(istream& is);
bool same_isbn(const Sales_item& that) const;
};
Sales_item::Sales_item(const std::string &book)
: data(book)
{
}
Sales_item::Sales_item(istream& is)
{
is>> (*this); //為什麼要這樣寫呢?? 如果是is>>data;我就可以了解了...
}
bool Sales_item::same_isbn(const Sales_item& that) const
{
return( data == that.data);
}
int main()
{
Sales_item item;
cout<< item.same_isbn("999")<<endl;
//上面這一行我一直都不能編譯成功...
//除非改成 item.same_isbn(string("999"))
cout<< item.same_isbn(cin)<<endl;
return 0;
}
有網友可以給一點提示嗎??
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.39.90.40
→
07/23 21:24, , 1F
07/23 21:24, 1F
※ 編輯: easterday 來自: 114.39.90.40 (07/23 21:30)
※ 編輯: easterday 來自: 114.38.232.217 (07/24 10:24)
推
07/25 02:35, , 2F
07/25 02:35, 2F
推
07/25 02:57, , 3F
07/25 02:57, 3F
→
07/25 03:00, , 4F
07/25 03:00, 4F
→
07/27 19:28, , 5F
07/27 19:28, 5F
→
07/27 19:28, , 6F
07/27 19:28, 6F