On 7/24/2015 11:28 AM, Riot wrote:
> If you're defining your template in the cpp file, you'll need to
> explicitly instantiate it somewhere with the types you're using for it.
> Alternatively, define it in the header and it'll be instantiated
> wherever it's used with whatever types it's used with.

It makes not the slightest difference whether the definition is in the 
XX.hpp header file or the YY.cpp source file. The same problem occurs.

Why should I have to explicitly instantiate the template for whatever 
type(s) I am using ? I am not exporting the instantiation from the 
shared library I create.

>
> On 24 July 2015 at 16:03, Edward Diener <eldlistmaili...@tropicsoft.com
> <mailto:eldlistmaili...@tropicsoft.com>> wrote:
>
>     On 7/24/2015 8:54 AM, Riot wrote:
>     > Where are you defining your template, in the header or the source? You
>     > may need to explicitly instantiate.
>
>     The template is being defined in the YY.cpp source file.
>
>      >
>      > On 24 Jul 2015 13:31, "Edward Diener"
>     <eldlistmaili...@tropicsoft.com
>     <mailto:eldlistmaili...@tropicsoft.com>
>      > <mailto:eldlistmaili...@tropicsoft.com
>     <mailto:eldlistmaili...@tropicsoft.com>>> wrote:
>      >
>      >     Before attempting to reduce my code to a small enough example
>     to post
>      >     here in its entirety I will give a description of the problem
>     to see if
>      >     anyone has encountered it in general. The problem is purely a
>     linker
>      >     problem.
>      >
>      >     I have an exported class in a shared library, called it XX in
>     header
>      >     file XX.hpp. From an executable's source file, called it YY.cpp I
>      >     include the class's header file where the class will show as
>     imported
>      >     and in the code in the source file I throw an exception with
>     an instance
>      >     of the class, as in:
>      >
>      >           throw XX(some_constructor_parameters);
>      >
>      >     This compiles and links without error.
>      >
>      >     If instead I use a template to throw an exception, such as:
>      >
>      >           template<class E> void throw_exception(E const & e) {
>     throw e; }
>      >
>      >     and then invoke it from my executable as:
>      >
>      >           throw_exception(XX(some_constructor_parameters));
>      >
>      >     I receive a linker error of the form:
>      >
>      >           YY.o: In function `SomeDecoratedName':
>      >           XX.hpp:27: undefined reference to `vtable for XX'
>      >           XX.hpp:27: undefined reference to `vtable for XX'
>      >
>      >     I realize that this is not a complete example but before
>     reducing my
>      >     code to the least possible example which will reproduce this
>     problem I
>      >     thought I would ask if anyone has encountered anything like
>     it, or has
>      >     any idea why using a template causes a linker error whereas
>     not using
>      >     the template links would link without any problems.
>
>
>
>     
> ------------------------------------------------------------------------------
>     _______________________________________________
>     Mingw-w64-public mailing list
>     Mingw-w64-public@lists.sourceforge.net
>     <mailto:Mingw-w64-public@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
>
>
>
> ------------------------------------------------------------------------------
>
>
>
> _______________________________________________
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>



------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to