Boost logo

Boost :

Subject: Re: [boost] [BOOST CORE C++ Feature] the super or base keyword for C++
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-05-01 13:25:53


On 01/05/2011 18:38, Marsh Ray wrote:
> On 05/01/2011 12:54 AM, tymofey wrote:
>>
>> >>I was wondering if it makes sense to add the well known super
>> or base keyword to the C++ language in a generic way. 
>>
>> C++ has multiple inheritance, while java and C# do not, so super would
>> be ambigous.
>
> class B1 { int i; float f; };
> class B2 { int j; float f; };
>
> class D : B1, B2
> {
> int i, j;
> float f;
>
> void fn()
> {
> ...
> int v = super::i; // refers to B1::i
> int w = super::j; // refers to B2::j
> float x = super::f; // error: ambiguous
> float y = super<B1>::f; // refers to B1::f
> float z = super<B2>::f; // refers to B2::f
> ...
> }
> };
>
> How ugly would the macros have to get to implement something like this
> with the current standards?

You'd have to use SFINAE to tell whether B1::j exists and use B2::j
otherwise.

Should be doable.


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