伊莉討論區

標題: 請問c++ operator的問題? [打印本頁]

作者: 0oBnBo0    時間: 2010-4-28 04:54 PM     標題: 請問c++ operator的問題?

本帖最後由 0oBnBo0 於 2010-4-28 05:06 PM 編輯

請問...下面的程式為什麼run不出來呀??
錯誤都出在  " cout<<!a; "這行 但是他寫的錯誤..看不懂呢..
  1. // test.cpp : 定義主控台應用程式的進入點。
  2. //

  3. #include "stdafx.h"
  4. #include "stdlib.h"
  5. #include <string>
  6. #include <iostream>
  7. #include <cctype>
  8. using namespace std;
  9. class Str
  10. {
  11.         public:
  12.                 Str();
  13.                 int operator! ();
  14.         private:
  15.                 string data;
  16.                 int len;
  17. };

  18. Str::Str(){
  19.         cin>>data;
  20. }

  21. int Str::operator!()
  22. {
  23.         len=0;
  24.         for(int i=0;data[i]!='\0';i++)
  25.                 len++;
  26.         return len;
  27. }


  28. int main(int argc, _TCHAR* argv[])
  29. {
  30.         string a;


  31.         Str();
  32.         cout<<!a;

  33.         system("pause");

  34.         return 0;
  35. }
複製代碼

作者: runeray2000    時間: 2010-4-28 06:35 PM

提示: 作者被禁止或刪除 內容自動屏蔽
作者: 0oBnBo0    時間: 2010-4-28 06:45 PM

哦...非常感謝大大的解答~
疑問瞬間消失了..xDD




歡迎光臨 伊莉討論區 (http://a401.file-static.com/) Powered by Discuz!