[問題]請教一下類別變數共用的問題... |
答題得分者是:smartboss
|
abdias
一般會員 發表:5 回覆:4 積分:1 註冊:2004-07-30 發送簡訊給我 |
假設我寫了一個母親的類別如下 mother.cpp
-----------------------------------
class mother
{
public:
int money;
}; 那我在BCB裡Form1裡寫了以下設定 Unit1.cpp
-------------------------------------------
#include
|
smartboss
初階會員 發表:19 回覆:93 積分:42 註冊:2004-12-29 發送簡訊給我 |
引言: mother.cpp ----------------------------------- class mother { public: int money; }; #include "Unit1.h" #include "Unit2.h"abdias 您好:小弟建意您將 #include "mother.cpp" 的層級拉高,同時建意您將class mother 放在mother.h 裡,因為小弟可能是才學粗淺所以第一次看過有人#include .cpp 的檔案,再來分別在您的 "Unit1.h" 裡引入 #include "mother.h" 並在class TForm1 裡宣告 { public: mother Brother1; }; 而在"Unit2.cpp" 裡引入 #include "Unit1.h" void __fastcall TForm2::Button1Click(TObject *Sender) { Form1->Brother1.money <----這就素葛葛的錢了 //我想在這裡取得哥哥類別的money變數 } |
abdias
一般會員 發表:5 回覆:4 積分:1 註冊:2004-07-30 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |