Click here to Skip to main content
15,887,392 members

Survey Results

Multiple Inheritence   [Edit]

Survey period: 17 Mar 2002 to 24 Mar 2002

Do you use multiple inheritence when programming?

OptionVotes% 
Yes, I often derive from multiple classes13513.80
Yes, I occasionally derive from multiple classes37638.45
Yes, I use classes that are derived from multiple classes (but don't create these classes myself)909.20
No - I see no need19219.63
No - the language I use doesn't support MI444.50
No - I intentionally avoid MI.14114.42



 
GeneralMI is useful, in same cases Pin
Mauro Gagna18-Mar-02 7:31
Mauro Gagna18-Mar-02 7:31 
Generali use it, but then i feel dirty Pin
Chris Losinger18-Mar-02 2:34
professionalChris Losinger18-Mar-02 2:34 
GeneralRe: i use it, but then i feel dirty Pin
Braulio Dez20-Mar-02 22:56
Braulio Dez20-Mar-02 22:56 
GeneralWTL Pin
CodeGuy18-Mar-02 2:08
CodeGuy18-Mar-02 2:08 
GeneralRe: WTL Pin
Joaquín M López Muñoz18-Mar-02 8:13
Joaquín M López Muñoz18-Mar-02 8:13 
GeneralRe: WTL Pin
CodeGuy18-Mar-02 8:24
CodeGuy18-Mar-02 8:24 
GeneralReal world examples Pin
Michael P Butler17-Mar-02 22:04
Michael P Butler17-Mar-02 22:04 
GeneralRe: Real world examples Pin
Navin18-Mar-02 3:40
Navin18-Mar-02 3:40 
GeneralRe: Real world examples Pin
Chris Losinger18-Mar-02 4:03
professionalChris Losinger18-Mar-02 4:03 
here's one i've used a few times:

i have a dialog class (CMyDlg) that uses some other class to do some processing. if that processing takes a long time, it's nice to show a progress dialog. but, only the worker class knows the progress status, so i need a way to get that info back to the dialog. in C, i'd just use a callback function (but in C++, that's not nice).

so, i make a little class like this:
class CProgressSink
{
public:
  virtual bool Progress(int iCurrent, int iTotal) = 0; 
};

and i multiply inherit my dialog class from CProgressSink, implementing the Progress function to do whatever progress updates i need (update a progress bar, show some text, pump some UI messages, etc).
bool CMyDlg::Progress(int iCur, int iTotal)
{
  TRACE("%d of %d\n", iCur, iTotal);
  return true; // could return false to cancel
}


at the same time, i've told my worker class to accept a pointer to a CProgressSink as a parameter in one of its ctors:

class CMyWorkerClass
{
   CMyWorkerClass (CProgressSink *pSink = NULL) {m_pSink = pSink;}
};


when i create the worker class object in CMyDlg, i can tell it where to send its bloody progress messages:
CMyWorkerClass thingy(this);


so when the worker class is working, it tests to see if it has a valid CProgressSink pointer. if it does, it calls CProgressSink::Progress with the current progress state.

the nice thing about this is that if i want to use the worker class from some other class (another worker class, for example), i just inherit that new class from CProgressSink and tell the worker class that the new class wants to be notified of progress events.

you could make CMyWorkerClass take a reference (or pointer) to a CMyDlg class, instead of adding the CProgressSink class. but that means you can only send Progress events back to CMyDlgs. while, for not much more work (like 5 lines more), you get the flexibility to send progress state to any class you can create.

now, some people would do this with a worker thread, but i think that's overkill in many cases. you could also do this with a C callback function (passing a "this" pointer around), but that's a bit scary.

-c



Smaller Animals Software, Inc.
You're the icing - on the cake - on the table - at my wake. Modest Mouse

GeneralRe: Real world examples Pin
Jamie Hale18-Mar-02 9:57
Jamie Hale18-Mar-02 9:57 
GeneralRe: Real world examples Pin
Ravi Bhavnani20-Mar-02 5:40
professionalRavi Bhavnani20-Mar-02 5:40 
GeneralDesign Patterns Pin
Braulio Dez20-Mar-02 22:57
Braulio Dez20-Mar-02 22:57 
GeneralWhy avoid it? Pin
Matt Newman17-Mar-02 16:31
Matt Newman17-Mar-02 16:31 
GeneralRe: Why avoid it? Pin
Nish Nishant17-Mar-02 16:46
sitebuilderNish Nishant17-Mar-02 16:46 
GeneralRe: Why avoid it? Pin
Vivek Rajan17-Mar-02 16:51
Vivek Rajan17-Mar-02 16:51 
GeneralRe: Why avoid it? Pin
Ravi Bhavnani17-Mar-02 16:52
professionalRavi Bhavnani17-Mar-02 16:52 
GeneralRe: Why avoid it? Pin
ColinDavies17-Mar-02 18:49
ColinDavies17-Mar-02 18:49 
GeneralRe: Why avoid it? Pin
James T. Johnson17-Mar-02 18:55
James T. Johnson17-Mar-02 18:55 
GeneralRe: Why avoid it? Pin
Uwe Keim17-Mar-02 19:33
sitebuilderUwe Keim17-Mar-02 19:33 
GeneralRe: Why avoid it? Pin
Michael Dunn17-Mar-02 20:46
sitebuilderMichael Dunn17-Mar-02 20:46 
GeneralRe: Why avoid it? Pin
Uwe Keim17-Mar-02 20:53
sitebuilderUwe Keim17-Mar-02 20:53 
GeneralRe: Why avoid it? Pin
Michael Dunn19-Mar-02 18:48
sitebuilderMichael Dunn19-Mar-02 18:48 
GeneralRe: Why avoid it? Pin
Andrew Torrance18-Mar-02 0:04
Andrew Torrance18-Mar-02 0:04 
GeneralRe: Why avoid it? Pin
Tom Archer20-Mar-02 5:17
Tom Archer20-Mar-02 5:17 
GeneralRe: Why avoid it? Pin
Joaquín M López Muñoz21-Mar-02 12:04
Joaquín M López Muñoz21-Mar-02 12:04 

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.