C++ et heritage

Top Page

Reply to this message
Author: Frederic Mantegazza
Date:  
To: ML Guilde
Subject: C++ et heritage
Bonjour,

Les personnes disposant d'un compilateur C++ autre que sous Linux (HP,
Sun, Irix...) pourrait-il me dire ce qu'ils ont comme erreurs sur la
compilation du fichier attache (avec l'option -c, car il n'y a pas la
definition des classes) ?

Je suis en train de voir quelles differences il y a entre g++/linux et
d'autres compilos...

Merci.

-- 
    Frederic

// heritage.c
// Tests de derivation public et private

class A {
private:
    int var1_private_A;
    int var2_private_A;
    void f1_private_A(void);
    void f2_private_A(void);


public:
    A();
    void f1_public_A(void);
    void f2_public_A(void);


protected:
    int var1_protected_A;
    int var2_protected_A;
    void f1_protected_A(void);
    void f2_protected_A(void);
};



class B {

private:
    int var1_private_B;
    int var2_private_B;
    void f1_private_B(void);
    void f2_private_B(void);


public:
    B();
    void f1_public_B(void);
    void f2_public_B(void);


protected:
    int var1_protected_B;
    int var2_protected_B;
    void f1_protected_B(void);
    void f2_protected_B(void);
};



class C_public_A : public A {
public:
    C_public_A() {
        var1_private_A = 0;        //    `int A::var1_private_A' is private
        var1_protected_A = 0;    //    Ok
        f1_private_A();            //    `void A::f1_private_A()' is private
        f1_public_A();            //    Ok
        f1_protected_A();        //    Ok
    };
};



class C_private_A : private A {
public:
    C_private_A() {
        var1_private_A = 0;        //    `int A::var1_private_A' is private
        var1_protected_A = 0;    //    Ok
        f1_private_A();            //    `void A::f1_private_A()' is private
        f1_public_A();            //    Ok
        f1_protected_A();        //    Ok
    };
};



class D : public C_public_A {
public:
    D() {
        var1_protected_A = 0;    //    Ok
        f1_private_A();            //    `void A::f1_private_A()' is private
        f1_public_A();            //    Ok
        f1_protected_A();        //    Ok
    };
};



class E : public C_private_A {
public:
    E() {;
        var1_protected_A = 0;    //    `int A::var1_protected_A' is protected
        f1_private_A();            //    `void A::f1_private_A()' is private
        f1_public_A();            //    `void A::f1_public_A()' is inaccessible
        f1_protected_A();        //    `void A::f1_protected_A()' is protected
    }
};



class U {
private:
    A a;
    B b;
    C_public_A c1;
    C_private_A c2;
    D d;
    E e;


public:
    U() {
        a.var1_private_A = 0;        //    `int A::var1_private_A' is private
        a.var1_protected_A = 0;        // `int A::var1_protected_A' is protected
        a.f1_private_A();            //    `void A::f1_private_A()' is private
        a.f1_public_A();            //    Ok
        a.f1_protected_A();            //    `void A::f1_protected_A()' is protected


        c1.var1_private_A = 0;        //    `int A::var1_private_A' is private
        c1.var1_protected_A = 0;    //    `int A::var1_protected_A' is protected
        c1.f1_private_A();            //    `void A::f1_private_A()' is private
        c1.f1_public_A();            //    Ok
        c1.f1_protected_A();        //    `void A::f1_protected_A()' is protected


        c2.var1_private_A = 0;        //    `int A::var1_private_A' is private
        c2.var1_protected_A = 0;    //    `int A::var1_protected_A' is protected
        c2.f1_private_A();            //    `void A::f1_private_A()' is private
        c2.f1_public_A();            //    `void A::f1_public_A()' is inaccessible
        c2.f1_protected_A();        //    `void A::f1_protected_A()' is protected


        d.var1_private_A = 0;        //    `int A::var1_private_A' is private
        d.var1_protected_A = 0;        //    `int A::var1_protected_A' is protected
        d.f1_private_A();            //    `void A::f1_private_A()' is private
        d.f1_public_A();            //    Ok
        d.f1_protected_A();            //    `void A::f1_protected_A()' is protected


        e.var1_private_A = 0;        //    `int A::var1_private_A' is private
        e.var1_protected_A = 0;        //    `int A::var1_protected_A' is protected
        e.f1_private_A();            //    `void A::f1_private_A()' is private
        e.f1_public_A();            //    `void A::f1_public_A()' is inaccessible
        e.f1_protected_A();            //    `void A::f1_protected_A()' is protected
    };
};