Re: [問題] 請問一下

看板C_and_CPP (C/C++)作者 (我愛阿蓉)時間16年前 (2009/07/31 17:54), 編輯推噓3(301)
留言4則, 2人參與, 最新討論串1/1
※ 引述《whisp1222 ()》之銘言: : class A{ : .... : public: : A(); : string get() const; : } : ========================== : class B{ : private: : A test; : private: : string try() const{ : test.get(); //這行會出現"像變數一樣被初始化"的錯誤 : } //請問我這種用法是哪邊觀念錯誤 : } 我改成 某x.h #include <iostream> using namespace std; class A{ public: A(){} string get() const { return string("GG"); } }; class B{ public: B(){} A test; private: string T() const{ return test.get(); //這行會出現"像變數一樣被初始化"的錯誤 } //請問我這種用法是哪邊觀念錯誤 }; main.cpp include 此.h B b cout<<b.test.get();可以正確執行 不知道你是不是誤打B的public打成private 還有沒有加上return之類的 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.207.187

07/31 17:56, , 1F
沒錯阿 我也是這樣寫 ~"~ 我在檢查一下看是不是哪個小
07/31 17:56, 1F

07/31 17:57, , 2F
地方漏掉了 感謝你的回答
07/31 17:57, 2F

07/31 18:17, , 3F
原來是我括號{}打成() ~>"<~ emacs裡面看起來好像
07/31 18:17, 3F

07/31 20:19, , 4F
是字型的關係吧 換個適合寫程式的字型...
07/31 20:19, 4F
文章代碼(AID): #1AShz5W5 (C_and_CPP)
文章代碼(AID): #1AShz5W5 (C_and_CPP)