看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《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
whisp1222:沒錯阿 我也是這樣寫 ~"~ 我在檢查一下看是不是哪個小 07/31 17:56
whisp1222:地方漏掉了 感謝你的回答 07/31 17:57
whisp1222:原來是我括號{}打成() ~>"<~ emacs裡面看起來好像 07/31 18:17
stonehomelaa:是字型的關係吧 換個適合寫程式的字型... 07/31 20:19