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’.

See also  5 Benefits of Using Time Tracking Software
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist