devxlogo

Templates

Templates

Question:
I’m porting a UNIX app to NT; one of the class hierarchies includes something like this:

template class base{    // stuff};template class derived :    public base,
public base{ // stuff};

When I compile it in MSVC6 I get the following error:

c:projects	est	est.cpp(14) : error C2500: 
'derived' : 'base'
is already a direct base class c:projects est est.cpp(17) : see reference to class
template instantiation 'derived' being compiled

How can I get around this?

Answer:
Your code is prefectly legal and should compile on every ANSI/ISO compliant compiler. Unfortunately, MS VC6.0 is not fully compliant yet and therefore, it refuses to compile this snippet. I would suggest using another compiler instead, such as Borland C++ Builder 4.0 for example (which blissfully compiles this code).

Alternatively, you can modify your code but it seems like you will need to do a lot of work because the changes will affect other components and classes that use class ‘derived’.

devx-admin

Share the Post: