Boost logo

Boost :

Subject: [boost] why the output is different?
From: Dongfei Yin (yin.dongfei_at_[hidden])
Date: 2009-04-09 11:38:27


I write some code like this:

#include <iostream>

using namespace std;

class Base1
{
public:
    typedef Base1 base;
    void f()
    {
        cout<<"Base1::f()"<<endl;
    }
};

class Base2
{
    typedef Base2 base;
public:
    void f()
    {
        cout<<"Base2::f()"<<endl;
    }
};

class A
    : public Base1
    , public Base2
{
public:
    A()
    {
        base::f();
    }
};

void main()
{
    A a;
}

the output is :
Base1::f()

But if the definition of class A modified like this,

class A
    : public Base2
    , public Base1
{
public:
    A()
    {
        base::f();
    }
};

the out will be:
Base2::f()

the output depends on the sequence of base class, that means the
"typedef" in base class is unreliable.
complier gives no warning.
I try these code at both VS2005 and VS2008, the result are same.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk