domingo, 22 de febrero de 2015

Herencia con Virtual Visual C++



#include <iostream>
#include <cstdlib>

using namespace std;

class Furniture
{
public:

 Furniture( int w ) : weight( w ) {}
 int weight;
};

class Bed : virtual public Furniture
{
public:

 Bed( int w = 0 ) : Furniture( w ) {}
 void sleep()
 {
  cout << "Dormir" << endl;
 }
};

class Sofa : virtual public Furniture
{
public:

 Sofa( int w = 0 ) : Furniture( w ) {}
 void watchTV()
 {
  cout << "Miro TV" << endl;
 }
};

class SleeperSofa : public Bed , public Sofa
{
public:

 SleeperSofa( int w ) : Furniture( w ) {}
 void foltOut()
 {
  cout << "Desplegable" << endl;
 }
};

int main( int argc , char *argv[] )
{
 SleeperSofa ss( 10 );

 cout << "Peso: " << ss.weight << endl;

 system("pause");
    return 0;
}


No hay comentarios:

Publicar un comentario