On 05.05.2010 00:02, * Öö Tiib:
> On 4 mai, 23:52, "Alf P. Steinbach"<al...@start.no> wrote:
>> I have code essentially equivalent to the inheritance below:
>>
>> <code>
>> #include<iostream>
>> using namespace std;
>>
>> class Base
>> {
>> public:
>> void foo() { cout<< "Non-const foo"<< endl; }
>> void foo() const { cout<< "Const foo"<< endl; }
>>
>> };
>>
>> template< class T>
>> class Derived: public T
>> {
>> public:
>> using T::foo;
>>
>> void m() { foo(); }
>>
>> };
>>
>> int main()
>> {
>> Derived< Base const>().m();}
>>
>> </code>
>>
>> Seems to work nicely, as if just ignoring the const qualification, and Comeau
>> doesn't complain (Comeau is usually right about such things).
>>
>> But I can't find anything in the standard supporting it, and indeed when T is
>> not a template parameter but a typedef for 'Base const' then g++ rejects it.
>>
>> So, is the above standard-conforming code or does it (at least formally) need to
>> "deconstify" the template parameter?
>
> You can not derive a class from "Base const" type. So that feels
> strange if you supply "Base const" as template argument that is
> expected to be used for base class of something by template.
The use case is a wrapper class, it must accept whatever kind of wrapped class.
> I vaguely
> remember standard saying something about ignoring cv-qualification at
> such places, but can not find it from real thing. From standpoint of
> style i would deconstify it anyway even if it was legal.
Yeah, perhaps better do that.
I still wonder if above is formally correct, though...
Cheers,
- Alf