Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dd

0 views
Skip to first unread message

等你說喜歡我

unread,
Aug 17, 2001, 8:06:50 AM8/17/01
to
※ 引述《Apya...@bbs.yuntech.edu.tw (烏拉諾斯)》之銘言:
: ※ 引述《WaSiVaG...@zoo.ee.ntu.edu.tw (等你說喜歡我)》之銘言:
: > 你好像沒仔細看我的問題內容 const int*ptrm=&A::m;
: > 這樣不是已經讓ptrm得到A:m的address 再dereference
: > 就得到它的值 這樣不算access嗎???
: The following error
: 1.A is a class type,but not a object.
: you don't declare a object of class A.
: In reality,neither a object of class A is allocated memory in the program.
不需要阿 請注意 A::m是static 跟物件是否生成無關!

: 2.the :: is a scope operator
: In the class It's just used by function which i know.
: the private variable is accessed by public function.

對阿 可是你沒注意到 那個private變數 A::m 竟然不是照這

個方式被存取到了

: 3.U can't specify any value in the undeclared object because the m's memory
: is unallocated by any object.
你的說法有問題

m 為const static type 在物件未生成前就一定要初始化它 它在物件未產生前

就存在 它的life time 就跟global variable , namespace 一樣 都是到

程式終了才結速

: 4.U don't specify the type of m.

有阿 const type阿 我不知道你的編譯器如何 不過在bcb5 sp1 上它直接

認定它為const int
--
[1;31mO [1;32mr [1;33mi [1;34mg [1;35mi [1;36mn [1;31m: [1;36m<不良牛牧場> [1;33mzoo.ee.ntu.edu.tw [1;32m(140.112.18.36) [m
[1;32mWelcome to SimFarm BBS [1;36m-- [m [1;31mFrom : [ [m211.72.86.17 [1;31m] [m

烏拉諾斯

unread,
Aug 17, 2001, 10:54:24 AM8/17/01
to
※ 引述《WaSiVaG...@zoo.ee.ntu.edu.tw (等你說喜歡我)》之銘言:

> 不需要阿 請注意 A::m是static 跟物件是否生成無關!

沒錯是跟生成無關 但是前提下只要是在private的變數
就得讓public的函數去存取
所以想得到static的值 還是得用public的函數去存取
只是static的值 有另外一種設定方式
以你的為例 const A::m=5; //不應該在class設定初值,otherwise=>error
//初值程式會自動設定為0

> 對阿 可是你沒注意到 那個private變數 A::m 竟然不是照這
> 個方式被存取到了

請看上面說的


> 你的說法有問題
> m 為const static type 在物件未生成前就一定要初始化它 它在物件未產生前
> 就存在 它的life time 就跟global variable , namespace 一樣 都是到
> 程式終了才結速

我修正了我的說法 請看上面 也謝謝你啦 我找到我錯誤的地方嚕

--
[m※ Origin: 雲林科技大學藍天使 <bbs.yuntech.edu.tw> [From: 140.125.32.51]

0 new messages