Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 9:04 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Multiple Inheritance
PostPosted: Thu Nov 13, 2008 3:10 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 1 time

Code:
#include <iostream>
#include "canvas.h"
#include "shape.h"
#include "genstack.h"

// Here is an object which has two base classes.  It is one of the shapes
// (a Square), and also a Stack_Elt so it can be put on the stack.
class StackedSquare: public Square, public Stack_Elt
{
    public:
        StackedSquare(int x, int y, int side): Square(x, y, side) { }
        void print(ostream& strm) const {
                strm << "Square[" << width << " @ " << origx << "x"
                     << origy << "]";
        }
};

main()
{
        Canvas c(35, 60);       // A place to draw.
        Stack s;                // A stack of squares.

        // Draw some squares, then put the on a stack.
        int size = 22;
        for(int m = 1; m <= 7; m++) {
                StackedSquare *ss = new StackedSquare(4*m, m + 1, size);
                size -= 3;
                s.push(ss);
                ss->draw(c);
        }

        // Pop them off, move 'em a bit, then draw them again.
        int move = 0;
        while(!s.empty()) {
                StackedSquare *ss = (StackedSquare *)s.pop();
                ss->translate(move, 25 + move);
                ++move;
                ss->draw(c);
                delete ss;
        }

        c.print(cout);
}


C++ allows multiple inheritance: A class may have more than one base class. Java does not permit multiple inheritance, but the Java interface system is actually a limited form of this. Java seems to have the right idea here. Interfaces seem to allow the useful applications of multiple inheritance, and forbid the stupid ones.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Code to open multiple links.
 help me! inheritance
 @AttributeOverride with Inheritance
 single table inheritance
 Javascript Validation On Multiple Select Lists
 Need Help for Java Chat - one server multiple clients..
 Inheritance in java
 Need Help about Inheritance
 Inheritance in c++
 Carrier Sense Multiple Access CSMA

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team