CCmdTarget Doesn't Work with Multiple Inheritance 
Author Message
 CCmdTarget Doesn't Work with Multiple Inheritance

Try doing this:

1. Derive a class "foo" multiply from CCmdTarget and a class "bar" that
contains a pure virtual function "blap".
2. Give foo a message map and put in a few message handlers.
3. Override blap in foo.
4. Now try calling foo.

Chances are, in a real world situation, when you try to call foo, the
program jumps to line 866 of CMDTARG.CPP (inside MFC), instead of the
overridden version of blap! I have been able to duplicate this bug with
nauseating regularity.

BTW: line 866 looks like this (in disassembly):

866:  IMPLEMENT_DYNAMIC(CCmdTarget, CObject)
5F48BC5B   push        ebp
5F48BC5C   mov         ebp,esp
5F48BC5E   push        ecx
5F48BC5F   mov         dword ptr [ebp-4],ecx
5F48BC62   mov         eax,offset

5F48BC67   mov         esp,ebp
5F48BC69   pop         ebp
5F48BC6A   ret

My question is.. Why in the hell does it jump here? Compiler bug?? Or are
they fiddling with my class in a {*filter*}, evil manner?
Does anyone know if multiple inheritance is somehow {*filter*} with CCmdTarget?

Thanks!



Tue, 01 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

I tried a test and it worked. You might want to check out MFC tech note #16.
In that example, they have a class that is multiply derived from CFrameWnd
and CWinApp. As you know, both of these are eventually derived from
CCmdTarget.

--
Cheers,
Tom Archer

page: http://www.*-*-*.com/

Quote:

>Try doing this:

>1. Derive a class "foo" multiply from CCmdTarget and a class "bar" that
>contains a pure virtual function "blap".
>2. Give foo a message map and put in a few message handlers.
>3. Override blap in foo.
>4. Now try calling foo.

>Chances are, in a real world situation, when you try to call foo, the
>program jumps to line 866 of CMDTARG.CPP (inside MFC), instead of the
>overridden version of blap! I have been able to duplicate this bug with
>nauseating regularity.

>BTW: line 866 looks like this (in disassembly):

>866:  IMPLEMENT_DYNAMIC(CCmdTarget, CObject)
>5F48BC5B   push        ebp
>5F48BC5C   mov         ebp,esp
>5F48BC5E   push        ecx
>5F48BC5F   mov         dword ptr [ebp-4],ecx
>5F48BC62   mov         eax,offset

>5F48BC67   mov         esp,ebp
>5F48BC69   pop         ebp
>5F48BC6A   ret

>My question is.. Why in the hell does it jump here? Compiler bug?? Or are
>they fiddling with my class in a {*filter*}, evil manner?
>Does anyone know if multiple inheritance is somehow {*filter*} with CCmdTarget?

>Thanks!



Wed, 02 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

I was trying to derive a class from CDialog and CCmdTarget and I kept getting
reference errors

V.


babbled on about:

Quote:
>->I tried a test and it worked. You might want to check out mfc tech note #16.
>->In that example, they have a class that is multiply derived from CFrameWnd
>->and CWinApp. As you know, both of these are eventually derived from
>->CCmdTarget.



Wed, 02 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

"babbled on"? Hey, my code works <G>

Seriously, why would you multiply derived from two classes when the second
class is already a base class for the first class??? You also failed to
mention exactly what "reference errors" you get.

--
Cheers,
Tom Archer

page: http://tarcher.home.mindspring.com

Quote:

>I was trying to derive a class from CDialog and CCmdTarget and I kept
getting
>reference errors

>V.


>babbled on about:

>>->I tried a test and it worked. You might want to check out mfc tech note
#16.
>>->In that example, they have a class that is multiply derived from
CFrameWnd
>>->and CWinApp. As you know, both of these are eventually derived from
>>->CCmdTarget.



Wed, 02 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

On Sat, 14 Feb 1998 19:08:41 -0500, "Tom Archer"

Quote:

>"babbled on"? Hey, my code works <G>

>Seriously, why would you multiply derived from two classes when the second
>class is already a base class for the first class??? You also failed to
>mention exactly what "reference errors" you get.

That would be illegal:

 struct A { void fun(); };
 struct B : A {};
 struct C : B, A
 {
    void fun()
    {
       A::fun(); // But which A?
    }
 };

That's illegal because there's no way to specify which A you want. You
can work around this problem through an intermediate class derived
from A:

 struct A { void fun(); };
 struct B : A {};
 struct A2 : A {};
 struct C : B, A2
 {
    void fun()
    {
       A::fun();  // Still ambiguous.
       B::fun();  // Fine.
       A2::fun(); // Ditto.
    }
 };

--
Doug Harrison



Thu, 03 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

Quote:
>Seriously, why would you multiply derived from two classes when the second
>class is already a base class for the first class??? You also failed to
>mention exactly what "reference errors" you get.

In my initial message, I made a mistake. I said to call "foo" -- which is
the name of a class -- when I should have said, call "blap" -- which is a
virtual function. Here is some source code to clarify:

class bar
{
public:
    virtual void Clunk() = 0;

Quote:
};

class foo : public CCmdTarget, public bar
{
public:
    virtual void Clunk();

    DECLARE_MESSAGE_MAP()

Quote:
};

...
BEGIN_MESSAGE_MAP(foo, CCmdTarget)
    // map some messages..
END_MESSAGE_MAP

When I make a call to clunk through a foo object, it jumps to line 866 of
CMDTARG.CPP:

866:  IMPLEMENT_DYNAMIC(CCmdTarget, CObject)
5F48BC5B   push        ebp
5F48BC5C   mov         ebp,esp
5F48BC5E   push        ecx
5F48BC5F   mov         dword ptr [ebp-4],ecx
5F48BC62   mov         eax,offset

5F48BC67   mov         esp,ebp
5F48BC69   pop         ebp
5F48BC6A   ret

Now. Tell me what the {*filter*} is going on here.
Thanks!



Fri, 04 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance


Fri, 19 Jun 1992 00:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

What is the sanest way to use inheritance  (multiple, or otherwise), and to
expose them to automation?
For non-gui automation servers, is CCmdTarget the appropriate base class to
use?
If so, what should / should not be over-ridden? (virtual functions)
What is the sanest way to expose an inherited classs functionality, without
having to created a function in my derived class (exposed to automation)
that forwards to my base class. (not directly exposed to automation).

If I expose my base class to automation, and derive a class from it, the
base class's
methods are (of course) exposed, if I choose that route, how do I expose the
methods of my base class??
(ie: if I derive a class from another automation class, VC does not produce
an .ODL for the derived class.
     How do I get VC 5.0, to create an ODL for the derived class? Can I
manually create one, and subsequently let VC 5.0, handle adding methods
like it normally does?



Sat, 05 Aug 2000 03:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance


Fri, 19 Jun 1992 00:00:00 GMT  
 CCmdTarget Doesn't Work with Multiple Inheritance

There are tonnes of other such problems in MFC source classes. Try
more and you'll start pulling your hair abort,retry,ignore sahil malik

On Fri, 13 Feb 1998 19:38:48 -0000, "Ken Simpson"

Quote:

>Try doing this:

>1. Derive a class "foo" multiply from CCmdTarget and a class "bar" that
>contains a pure virtual function "blap".
>2. Give foo a message map and put in a few message handlers.
>3. Override blap in foo.
>4. Now try calling foo.

>Chances are, in a real world situation, when you try to call foo, the
>program jumps to line 866 of CMDTARG.CPP (inside MFC), instead of the
>overridden version of blap! I have been able to duplicate this bug with
>nauseating regularity.

>BTW: line 866 looks like this (in disassembly):

>866:  IMPLEMENT_DYNAMIC(CCmdTarget, CObject)
>5F48BC5B   push        ebp
>5F48BC5C   mov         ebp,esp
>5F48BC5E   push        ecx
>5F48BC5F   mov         dword ptr [ebp-4],ecx
>5F48BC62   mov         eax,offset

>5F48BC67   mov         esp,ebp
>5F48BC69   pop         ebp
>5F48BC6A   ret

>My question is.. Why in the hell does it jump here? Compiler bug?? Or are
>they fiddling with my class in a {*filter*}, evil manner?
>Does anyone know if multiple inheritance is somehow {*filter*} with CCmdTarget?

>Thanks!



Mon, 14 Aug 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. CCmdTarget and Multiple Inheritance

2. MFC doesn't work with multi-inheritance library

3. Why my multiple CFileDialog doesn't work ?

4. Multiple inheritance with MFC ??? Seems not to work

5. SaveBarState (WORKS) LoadBarState(Doesn't Work)?

6. GetPrivateProfileSectionNames works in 2000, doesn't work in 98 or ME

7. Tooltip works and then doesn't work

8. Q147740 CWnd work-around doesn't work with control that uses lic file

9. Calling ADO's GetRows() from VC doesn't work

10. Don't know why this doesn't work, but

11. TERMWAIT Win 3.1 sample doesn't work under '95

12. Assertion in CCmdTarget::~CCmdTarget()

 

 
Powered by phpBB® Forum Software