Ryan's District
September 08, 2008, 06:00:28 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length

There are currently users in chat
News: You are not allowed to view links.
Register or Login
How to Unlock Nokia mobile Phones

You are not allowed to view links.
Register or Login
Request any TV Show / series / Episodes / movie and we will get it for you for free

 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: C++ tips - Callbacks and multiple inheritance, part I  (Read 3705 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« on: October 07, 2006, 03:00:55 AM »

This example is based upon "Subobject Members", Stephen Dewhurst,
C++ Report, V5 N3. This is part 1 of a multipart example.

Suppose that you need to model an engine and a button. When the
button is pressed, the engine is supposed to start. One convenient
way to handle this "callback" relationship is to use multiple
inheritance (we do this in Guide, SES/design, and Objectbench).

.................................................................

class ButtonCallback {
  public:
    virtual void callback () = 0;
};

.................................................................

class Button {
    ButtonCallback& target;
  public:
    Button (ButtonCallback& bcb) : target(bcb) {}

    virtual void press ();
};

void Button :: press ()
{
    target.callback ();
}

.................................................................

class Engine : public ButtonCallback {
    // ...
  public:
    void start ();
    virtual void callback ();
};


void Engine :: callback ()
{
    start ();
}

Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
   

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: TOP SEO Directory - Online Job Maker - List of Advertisers - BIG VENUE

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.723 seconds with 31 queries.

Google visited last this page September 04, 2008, 05:18:38 PM