Does it make sense to export a template class def?

B

Ben

Hi.

I am currently trying to move compilers (VC6 -> VC7 in fact) and I'm
having a few problems (so far exclusively to do with better standard
conformance).

Anyhow, whilst rebuilding a third-party library (let's call it library
B) I'm getting some unresolved externals when it tries to use another
library (library A) that includes code like this in a header:

template<class T>
class EXPORT AClassName
{
...
};


(BTW: EXPORT is defined as __declspec(dllexport) or
__declspec(dllimport) depending on which lib I'm building.)

I first assumed that library A wasn't actually exporting the class
(some screw-up with the def of EXPORT I thought). But after checking
that was OK I realised (doh!) that this is template class and
therefore all members are fully defined in the header file.

So this made we wonder - why might the above class have the EXPORT
keyword in there at all? Surely it's redundant for a template class?

Confused,
Ben.
 
J

Jakob Bieling

Ben said:
Hi.

I am currently trying to move compilers (VC6 -> VC7 in fact) and I'm
having a few problems (so far exclusively to do with better standard
conformance).

Anyhow, whilst rebuilding a third-party library (let's call it library
B) I'm getting some unresolved externals when it tries to use another
library (library A) that includes code like this in a header:

template<class T>
class EXPORT AClassName
{
...
};


(BTW: EXPORT is defined as __declspec(dllexport) or
__declspec(dllimport) depending on which lib I'm building.)

I first assumed that library A wasn't actually exporting the class
(some screw-up with the def of EXPORT I thought). But after checking
that was OK I realised (doh!) that this is template class and
therefore all members are fully defined in the header file.

So this made we wonder - why might the above class have the EXPORT
keyword in there at all? Surely it's redundant for a template class?


Either because someone writing this did not understand templates well
enough, or I am missing something. I would not bother and just remove the
EXPORT part from the template. The class is defined as if it was your own,
no need to put any stuff around it.

hth
 
B

Ben

Either because someone writing this did not understand templates well
enough, or I am missing something. I would not bother and just remove the
EXPORT part from the template. The class is defined as if it was your own,
no need to put any stuff around it.

hth

Looks like it's the former - I tried just removing the export def and
all seems well.

Cheers for the confirmation!

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top