By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Does it make sense to export a template class def?

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Ben" <be****@hotmail.com> wrote in message
news:a6**************************@posting.google.c om...
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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #2

P: n/a
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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.