Visual C++: Exemple d’héritage

Author:


{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;
}


Leave a Reply

Your email address will not be published. Required fields are marked *