作者QQ29 (我愛阿蓉)
看板C_and_CPP
標題Re: [問題] 請問一下
時間Fri Jul 31 17:54:12 2009
※ 引述《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