Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effects of a const base class [duplicate]

What is the actual effect of the following construct:

class Base { /* ... */ };

template<class T>
class Derived : public T { /* ... */ };

int main() {
    Derived<const Base> d;
    // ...
}

Does the Derived class only have access to the const-part of the interface of Base? My first tests indicate that there's actually no effect at all. Why?

Thanks!

like image 778
phlipsy Avatar asked Mar 23 '13 07:03

phlipsy


1 Answers

My guess is that the const is ignored, because if you try to write

class Derived : public const Base

the program doesn't compile.

EDIT:

frozenkoi gave the relevant part of the standard in the comments:

"A typedef-name (7.1.3) that names a class type, or a cv-qualified version thereof, is also a class-name. If a typedef-name that names a cv-qualified class type is used where a class-name is required, the cv-qualifiers are ignored. A typedef-name shall not be used as the identifier in a class-head." §9.1

like image 178
alestanis Avatar answered Oct 19 '22 11:10

alestanis