Does it make sense to export a template class def?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    Does it make sense to export a template class def?

    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(dlle xport) or
    __declspec(dlli mport) 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.
  • Jakob Bieling

    #2
    Re: Does it make sense to export a template class def?

    "Ben" <ben_ml@hotmail .com> wrote in message
    news:a62a8d2a.0 308080304.754a0 1e4@posting.goo gle.com...[color=blue]
    > 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(dlle xport) or
    > __declspec(dlli mport) 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?[/color]


    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)


    Comment

    • Ben

      #3
      Re: Does it make sense to export a template class def?

      > Either because someone writing this did not understand templates well[color=blue]
      > 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[/color]

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

      Cheers for the confirmation!

      Ben

      Comment

      Working...