deriving from an STL type 
Author Message
 deriving from an STL type

This is more of a general template question...
How do you separate the template class member definitions and
declarations? I'm having linker problems. Stroustroup says you need to
"export" the definition, but that doesn't work with MSVC5, i tried
_export and dllexport...
i.e. what I want is to have something like

tclass.h, with
template < typename T > class Ct
bool isOk( );

and tclass.cpp with
template< typename T >
bool Ct<T>::isOk( ) { return true; }

here linker would say isOk is undefined.



Mon, 30 Apr 2001 03:00:00 GMT  
 deriving from an STL type
Alen !

You are both right and wrong.
In the original definition of the language, a template class in C++ couldn't
be separated into a declaration & definition (H file & CPP file). This is
the case with MSVC  5.0, and other compilers (Borland 5.0, Watcom 11.0).

The reason for the behavior, is that templates are resolved during
pre-processing: the pre-compiler finds all instances of the template for a
given type, and inserts the type into the code. That is the reason templates
are memory consuming - for each object based on a new type, another instance
of the class is created.

In the newer, standardized C++, as described in "The C++ Programming
Language, 3rd edition", Stroustrup  uses the export directive (although it
doesn't appear in the C++ keywords table at Appendix A, p.794 !). It isn't
supported by MSVC5.0, and by most compilers yet (the compilers are yet to
catch-up with the language).

Noam Sigal

Fri, 04 May 2001 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Type Casting between Base and Derived Type (Serialization of objects with Type members)

2. Casting to/from STL types to MFC types

3. base and derived insert into STL list

4. BUG: STL derived class never calls the constructor

5. Exporting class from DLL when class derives from STL

6. Deriving from a STL for a DLL exported function

7. = operator implementation in STL derived class

8. Virtual Functions for Derived Objects held in STL Maps

9. Derived return types and virtual functions

10. Derive from enum type?

11. Casting to Derived type

12. Collection class that can store derived types


Powered by phpBB® Forum Software