Click here to Skip to main content
15,890,609 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: about Coordinate Map Mode and compatible DC ??? Pin
AntonlioX25-Jun-05 19:25
AntonlioX25-Jun-05 19:25 
GeneralRe: about Coordinate Map Mode and compatible DC ??? Pin
Jose Lamas Rios26-Jun-05 11:28
Jose Lamas Rios26-Jun-05 11:28 
GeneralRe: about Coordinate Map Mode and compatible DC ??? Pin
Pazzuzu5-Jul-05 1:20
Pazzuzu5-Jul-05 1:20 
GeneralCList For Non CObject derived class (vs CTypedPtrList) Pin
yccheok24-Jun-05 23:11
yccheok24-Jun-05 23:11 
GeneralRe: CList For Non CObject derived class (vs CTypedPtrList) Pin
ThatsAlok25-Jun-05 1:06
ThatsAlok25-Jun-05 1:06 
GeneralStrange dynamic_cast problem Pin
yccheok24-Jun-05 22:11
yccheok24-Jun-05 22:11 
GeneralRe: Strange dynamic_cast problem Pin
squidev25-Jun-05 8:18
squidev25-Jun-05 8:18 
GeneralRe: Strange dynamic_cast problem Pin
yccheok25-Jun-05 19:41
yccheok25-Jun-05 19:41 
Can you please let me know how I can enable RTTI for the project? Please note that for the classes which my CDocument inheritance from, I created by hand.

Here is my details:

I have an abstract class named CObserver and a concrete class named CSubject. The purpose of having this two classes is that, some interesting event will always happen in subject. observer is a guy which is interested in the event in subject. subject will notify all the observers attached to it whenever an event happen.



---------------------------------------------------------------------

class CObserver {



public:

virtual ~CObserver();

virtual void Update(CSubject *s) const=0;



protected:

CObserver();

};



class CSubject {



public:

virtual ~CSubject();

virtual void Attach(CObserver *o);

virtual void Detach(CObserver *o);

virtual void Notify();



protected:

CSubject();



private:

CList<cobserver*, cobserver*=""> _observers;

};

---------------------------------------------------------------------



Now, I need to monitor a IO port. Then, I need to notify my CDocument whenever there is some IO activity. Hence, I create an CIOMonitor class which is single inheritance from CSubject.



// Please note that I remove most of the members. Only leave those which is related to this bug

class CIOMonitor : public CSubject

{

int GetInt() const;

}



I use Wizard in VC++ to create MDI project. Then, for the CCatchbugDoc (multiple inheritance from CDocument and CObserver). This is because CCatchbugDoc will be interested in the event happen in CIOMonitor



class CCatchbugDoc : public CDocument, public CObserver

{

public:

virtual void Update(CSubject *s) const;

};



Please note here is the root of evil



void CCatchbugDoc::Update(CSubject *s) const

{

/* Everything work fine with this unsafe casting */

/* But dynamic casting just prompt me a runtime error */

/**/

/* CIOMonitor *p = (CIOMonitor *)s; */

CIOMonitor *p = dynamic_cast<ciomonitor *="">(s);



if(p == NULL) {

AfxMessageBox("unknown error during dynamic cast");

return;

}



CString string;

string.Format("Nofity. CIOMonitor: %i", p->GetInt());



AfxMessageBox(string);

}



Here is my suspection



1. In VC++, CCatchbugDoc is created using dynamic creation. Initially, CCatchbugDoc is single inheritance from CDOcument. The following macro is added by VC++ wizard to enable dynamic creation:



IMPLEMENT_DYNCREATE(CCatchbugDoc, CDocument)



Now, I make CCatchbugDoc as multiple inheritance (CDOcument and CObserver). But I still use back the same



IMPLEMENT_DYNCREATE(CCatchbugDoc, CDocument)



Can this be the possible root cause of bug?



Thank you!



-cheok
GeneralRe: Strange dynamic_cast problem Pin
squidev26-Jun-05 3:50
squidev26-Jun-05 3:50 
GeneralRe: Strange dynamic_cast problem Pin
yccheok26-Jun-05 5:25
yccheok26-Jun-05 5:25 
GeneralIPersistStream[Init] Pin
CodingBadger24-Jun-05 16:47
CodingBadger24-Jun-05 16:47 
GeneralDisabling console Pin
Anonymous24-Jun-05 15:48
Anonymous24-Jun-05 15:48 
GeneralRe: Disabling console Pin
Nathan Addy25-Jun-05 8:07
Nathan Addy25-Jun-05 8:07 
Questionhow to download a web page with pictures Pin
Mohsen Saad24-Jun-05 14:43
Mohsen Saad24-Jun-05 14:43 
AnswerRe: how to download a web page with pictures Pin
Ravi Bhavnani24-Jun-05 16:53
professionalRavi Bhavnani24-Jun-05 16:53 
GeneralRemoving references to expired user accounts Pin
aravinthv24-Jun-05 11:35
aravinthv24-Jun-05 11:35 
GeneralRe: Help wanted with TC_ITEM Pin
Jose Lamas Rios24-Jun-05 17:07
Jose Lamas Rios24-Jun-05 17:07 
GeneralRe: Help wanted with TC_ITEM Pin
cgb14328-Jun-05 5:35
cgb14328-Jun-05 5:35 
GeneralNeed help solving Printing Bug Pin
Jorgen E.24-Jun-05 10:22
Jorgen E.24-Jun-05 10:22 
GeneralRe: Need help solving Printing Bug Pin
Jose Lamas Rios26-Jun-05 18:24
Jose Lamas Rios26-Jun-05 18:24 
GeneralWierd Spy++ issue Pin
Abhishek Karnik24-Jun-05 10:18
Abhishek Karnik24-Jun-05 10:18 
GeneralNeed help solving Bug when opening files Pin
Jorgen E.24-Jun-05 10:08
Jorgen E.24-Jun-05 10:08 
GeneralDisable edit box in dialog Pin
arkady460724-Jun-05 9:19
arkady460724-Jun-05 9:19 
GeneralRe: Disable edit box in dialog Pin
Jose Lamas Rios24-Jun-05 9:21
Jose Lamas Rios24-Jun-05 9:21 
GeneralRe: Disable edit box in dialog Pin
arkady460724-Jun-05 9:50
arkady460724-Jun-05 9:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.