Click here to Skip to main content
15,888,590 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Calling a method with the pointer to a base class Pin
_Flaviu11-Jul-16 1:59
_Flaviu11-Jul-16 1:59 
GeneralRe: Calling a method with the pointer to a base class Pin
leon de boer11-Jul-16 7:16
leon de boer11-Jul-16 7:16 
Questionreguired fast printing Pin
patilvaibhavrao7-Jul-16 20:39
patilvaibhavrao7-Jul-16 20:39 
AnswerRe: reguired fast printing Pin
Richard MacCutchan7-Jul-16 21:05
mveRichard MacCutchan7-Jul-16 21:05 
AnswerRe: reguired fast printing Pin
FriendOfAsherah7-Jul-16 22:25
FriendOfAsherah7-Jul-16 22:25 
AnswerRe: reguired fast printing Pin
leon de boer8-Jul-16 3:22
leon de boer8-Jul-16 3:22 
AnswerRe: reguired fast printing Pin
Patrice T8-Jul-16 10:42
mvePatrice T8-Jul-16 10:42 
QuestionOverloading methods with identical content in lot of derived classes Pin
FriendOfAsherah7-Jul-16 19:38
FriendOfAsherah7-Jul-16 19:38 
Following problem:
I have a base class "B" in which there are some methods M1(),M2... Mn().
C++
class B { 
public 
//... some other methods
// 
   virtual void M1();    
   virtual void M2(); 
   // ...
   virtual void Mn(); 
}; 


now I have multiple derived classes:
C++
class Ca1 : public B { .... };
class Ca2 : public B { .... };
//...
class Can : public B { .... };


and again derived each from above
C++
class Cb1 : public Ca1 { .... };
class Cb2 : public Ca2 { .... };
//...
class Cbn : public Can { .... };


And at last another deriving step by
C#
class Cc1 : public Cb1 { .... };
class Cc2 : public Cb2 { .... };
//...
class Ccn : public Cb3 { .... };


Now the Question:
each of the derived last classes will override the methods M1, M2, M3 ...Mn... with the same functional content!

C++
class Cc1 : public Cb1 {
virtual void M1() { /* code m1 */ } override;
virtual void M2() { /* code m2 */ } override;
...
virtual void M3() { /* code m3 */ } override;
};
class Cc2 : public Cb2 {
virtual void M1() { /* code m1 */ } override;
virtual void M2() { /* code m2 */ } override;
...
virtual void M3() { /* code m3 */ } override;
};

... this identical with identical code m1, m2 ... forall classes derived
Cc1, Cc2, ... Ccn!

How to best avoid to copy this M1, ... Mn block for method overriding into each derived class?

The existing code packed everthing into a macro and copied this into the classes
like
C++
#define DRIVED_METHODS \
virtual void M1 { /* code m1 */ } \

and so on which results in horrible undebugable code!

Using multiple inheritance does not work:
C++
class Cc1 : public Cb1, public CMpack
{};
class Mpack { void M1 {}; ... }; 


The only idea was to "map" each method to a class that collects these common methods

C++
class Mcommon {
virtual void m_M1() { };
virtual void m_M2() {}; 
// ... etc 
}

class Cc1 : public Mcommon 
{ 
virtual void M1() { Mcommon::m_M1() ; } override 
// ... M2 and so on 
};
I know that there must be a mistake in the whole design
but Im not allowed to change much because nobody knows why the anchestor did such a design and sideeffects on changing code may happen.

Have searched the web but best solution I got is the "Mapping"

parameters, return types in M1...Mn have been simplyfied to void, empty in the text above
QuestionRe: Overloading methods with identical content in lot of derived classes Pin
CPallini7-Jul-16 21:09
mveCPallini7-Jul-16 21:09 
AnswerRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah7-Jul-16 21:54
FriendOfAsherah7-Jul-16 21:54 
QuestionRe: Overloading methods with identical content in lot of derived classes Pin
CPallini7-Jul-16 22:37
mveCPallini7-Jul-16 22:37 
AnswerRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah7-Jul-16 22:51
FriendOfAsherah7-Jul-16 22:51 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
CPallini7-Jul-16 23:37
mveCPallini7-Jul-16 23:37 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah8-Jul-16 3:45
FriendOfAsherah8-Jul-16 3:45 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
CPallini8-Jul-16 9:00
mveCPallini8-Jul-16 9:00 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah10-Jul-16 20:16
FriendOfAsherah10-Jul-16 20:16 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
ellegonzalez18-Aug-16 22:59
ellegonzalez18-Aug-16 22:59 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
leon de boer8-Jul-16 3:01
leon de boer8-Jul-16 3:01 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah8-Jul-16 3:47
FriendOfAsherah8-Jul-16 3:47 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
leon de boer8-Jul-16 18:25
leon de boer8-Jul-16 18:25 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah10-Jul-16 20:32
FriendOfAsherah10-Jul-16 20:32 
AnswerRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah13-Jul-16 0:45
FriendOfAsherah13-Jul-16 0:45 
AnswerRe: Overloading methods with identical content in lot of derived classes Pin
Krishnakumartg19-Jul-16 20:14
Krishnakumartg19-Jul-16 20:14 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah19-Jul-16 23:06
FriendOfAsherah19-Jul-16 23:06 
QuestionCMFCRibbonBar High DPI Pin
Paul Harrison 26-Jul-16 7:12
Paul Harrison 26-Jul-16 7:12 

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.