Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Visual C++: Exemple d’héritage


{filelink=13221}

#include "stdafx.h"
using namespace System;
 
class Carre
{
public:
    Int32 Surface()
    {
        return Dims * Dims;
    }
 
    Int32 Dims;
};
 
class Cube : public Carre // La classe Cube hérite les membres publique de la clsse Carree
{
public:
    Int32 Volume()
    {
        return Surface() * Dims;
    }
};
 
int main(void)
{
    Cube *cube = new Cube();
    cube->Dims = 6;
    Console::WriteLine("Dimension= "+cube->Dims);
    Console::WriteLine("Surafce= "+cube->Surface());
    Console::WriteLine("Volume= "+cube->Volume());
	Console::ReadLine();
    return 0;
}

No comments yet.

Leave a Comment