Total members 11895 |It is currently Wed Dec 04, 2024 10:01 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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.
cpp 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);
}




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Multiple Inheritance
 Inheritance in c++     -  
 inheritance in c++     -  
 What is Inheritance?!!     -  
 help me! inheritance     -  
 Inheritance C++ Example     -  
 Need Help about Inheritance     -  
 @AttributeOverride with Inheritance     -  
 Inheritance in java     -  
 single table inheritance     -  
 Inheritance & polymorphism checker code     -  



Topic Tags

C++ OOP
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com