🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by smedley Tue, 03 Nov 1992 07:13
Odd multiple inheritance behaviour
#70
Author: smedley
Date: Tue, 03 Nov 1992 07:13
47 lines
1525 bytes
% gcc -v
Reading specs from
/usr/local/lib/gcc-lib/hppa1.0-hp9k835-hpux8.0/2.2.2/specs
gcc version 2.2.2
% cat multiple.C
#include <iostream.h>

class foo {
public:
        foo(int i) {k = i;}
protected:
        int k;
};

class bar_1 : public foo {
public:
        bar_1(int i) : foo(i) {}
        int get_k() {return k;}
};

class bar_2 : public foo {
public:
    bar_2(int i) : foo(i) {};
        int get_k() {return k;}
};

class multiple : public bar_1, public bar_2 {
public:
        multiple(int i1, int i2) : bar_1(i1), bar_2(i2) {}
        void print() {
                cout << "bar_1::k -> " << bar_1::k << "\n";
                cout << "bar_2::k -> " << bar_2::k << "\n";
                cout << "bar_1::get_k() -> " << bar_1::get_k() << "\n";
                cout << "bar_2::get_k() -> " << bar_2::get_k() << "\n";
        }
};

main() {
        multiple m(1,2);
        m.print();
}
% g++ multiple.C
% a.out
bar_1::k -> 1
bar_2::k -> 1              ****** Should be 2
bar_1::get_k() -> 1
bar_2::get_k() -> 2
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads