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

請問IsKindOf的問題..

0 views
Skip to first unread message

哈皮龍

unread,
Dec 1, 1997, 3:00:00 AM12/1/97
to

請問一下,我IsKindOf是哪裡用錯呀???
請各位高手能幫幫忙??
我樣依照不同的class來run不同的Draw

// define variable
CScribbleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// The view delegates the drawing of individual strokes to
// CStroke::DrawStroke().
CTypedPtrList<CObList,CStroke*>& strokeList = pDoc->m_strokeList;

POSITION pos = strokeList.GetHeadPosition();
1.
////////////////
//因為假設strokeList有很多class所組成的話,這樣子做的話
//我就可以依據不同的class,來呼叫不同的DrawStroke.....
//可是這樣寫run的結果是錯誤,且系統會要我強制離開程式
//請問各位高手能幫幫我嘛??


if ( (
strokeList.GetNext(pos)->IsKindOf( RUNTIME_CLASS(CStroke) )
) != 0 )
{
CStroke* pStroke = strokeList.GetAt(pos) ;
pStroke->DrawStroke(pDC);
}
2.
///////////////////////
//這樣寫run的結果是對的就正確,可是我卻不想要這樣,
//因為假設strokeList有很多class所組成的話,這樣子做
//就太沒彈性了....

CStroke* pStroke = strokeList.GetNext(pos);
if ( (
pStroke->IsKindOf( RUNTIME_CLASS(CStroke) )
) != 0 )
{
pStroke->DrawStroke(pDC);

}

謝謝...
--
※ Origin: 楓橋驛站(bbs.cs.nthu.edu.tw) ◆ From: 210.66.158.194

四眼的王蟲

unread,
Dec 2, 1997, 3:00:00 AM12/2/97
to

Richard...@bbs.cs.nthu.edu.tw (哈皮龍) wrote:

>1.
>////////////////
>//因為假設strokeList有很多class所組成的話,這樣子做的話
>//我就可以依據不同的class,來呼叫不同的DrawStroke.....
>//可是這樣寫run的結果是錯誤,且系統會要我強制離開程式
>//請問各位高手能幫幫我嘛??
>
>
> if ( (
> strokeList.GetNext(pos)->IsKindOf( RUNTIME_CLASS(CStroke) )
> ) != 0 )
> {
> CStroke* pStroke = strokeList.GetAt(pos) ;
> pStroke->DrawStroke(pDC);
> }

問題可能是這樣的: GetNext(pos) 執行完畢後會將 pos 所指的
object 傳出來, 同時會將 pos 的值指向下一個 object, 也就是說
你程式裡 GetNext(pos) 與 GetAt(pos) 這兩行裡的 pos 其實是指向
不同的 object 的, 且 GetAt(pos) 的 pos 可能為 NULL。


>2.
>///////////////////////
>//這樣寫run的結果是對的就正確,可是我卻不想要這樣,
>//因為假設strokeList有很多class所組成的話,這樣子做
>//就太沒彈性了....
>
>CStroke* pStroke = strokeList.GetNext(pos);
> if ( (
> pStroke->IsKindOf( RUNTIME_CLASS(CStroke) )
> ) != 0 )
>{
> pStroke->DrawStroke(pDC);
>
>}

這個寫法是正確的寫法, 你覺得哪裡不妥嗎?

四眼的王蟲

--
生命是在黑暗中閃爍的光

Jimmy_Lee

unread,
Dec 3, 1997, 3:00:00 AM12/3/97
to

哈皮龍 <Richard...@bbs.cs.nthu.edu.tw> 次寫入到主題
<3Lk8kS$u...@bbs.cs.nthu.edu.tw>...
> 請問一下,我IsKindOf是哪裡用錯呀???
> 請各位高手能幫幫忙??
> 我樣依照不同的class來run不同的Draw

>
> if ( (
> strokeList.GetNext(pos)->IsKindOf( RUNTIME_CLASS(CStroke) )
^^^^^^^^^^^^^^^^^^^^^^^

用 GetNext(pos) 後, pos 會指到下一個 object

> ) != 0 )
> {
> CStroke* pStroke = strokeList.GetAt(pos) ;

^^^^^^^^^^^^^^^^^^^^^

pStroke 已不是上一個 checking 的 object.

> pStroke->DrawStroke(pDC);
> }

建議你的 DrawStroke 做成 virtual function

--
<Jimm...@mail.syscom.com.tw>

0 new messages