Click here to Skip to main content
14,867,295 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
Member_Flaviu11-Jul-16 1:59 
GeneralRe: Calling a method with the pointer to a base class Pin
leon de boer11-Jul-16 7:16
Memberleon de boer11-Jul-16 7:16 
Questionreguired fast printing Pin
patilvaibhavrao7-Jul-16 20:39
Memberpatilvaibhavrao7-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
MemberFriendOfAsherah7-Jul-16 22:25 
AnswerRe: reguired fast printing Pin
leon de boer8-Jul-16 3:22
Memberleon 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
MemberFriendOfAsherah7-Jul-16 19:38 
Following problem:
I have a base class "B" in which there are some methods M1(),M2... Mn().
class B { 
public 
//... some other methods
// 
   virtual void M1();    
   virtual void M2(); 
   // ...
   virtual void Mn(); 
}; 


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


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


And at last another deriving step by
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!

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
#define DRIVED_METHODS \
virtual void M1 { /* code m1 */ } \

and so on which results in horrible undebugable code!

Using multiple inheritance does not work:
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

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
MemberFriendOfAsherah7-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
MemberFriendOfAsherah7-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
MemberFriendOfAsherah8-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
MemberFriendOfAsherah10-Jul-16 20:16 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
ellegonzalez18-Aug-16 22:59
Memberellegonzalez18-Aug-16 22:59 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
leon de boer8-Jul-16 3:01
Memberleon de boer8-Jul-16 3:01 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah8-Jul-16 3:47
MemberFriendOfAsherah8-Jul-16 3:47 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
leon de boer8-Jul-16 18:25
Memberleon de boer8-Jul-16 18:25 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah10-Jul-16 20:32
MemberFriendOfAsherah10-Jul-16 20:32 
AnswerRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah13-Jul-16 0:45
MemberFriendOfAsherah13-Jul-16 0:45 
AnswerRe: Overloading methods with identical content in lot of derived classes Pin
Krishnakumartg19-Jul-16 20:14
MemberKrishnakumartg19-Jul-16 20:14 
GeneralRe: Overloading methods with identical content in lot of derived classes Pin
FriendOfAsherah19-Jul-16 23:06
MemberFriendOfAsherah19-Jul-16 23:06 
QuestionCMFCRibbonBar High DPI Pin
Paul Harrison 26-Jul-16 7:12
MemberPaul 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.