www.digitalmars.com         C & C++   DMDScript  

c++ - Template linking bug.

Hi,

With the following files:

test.hpp:

     template <class Derived>
     struct singleton {
         static void instance() { static Derived the_inst; }
         ~singleton() {}
     };

     struct test : singleton<test>
     {
     };

test1.cpp:

     #include "test.hpp"

     void test1()
     {
         test::instance();
     }

test2.cpp:

     #include "test.hpp"

     void test2()
     {
         test::instance();
     }

When I compile them with:

     dmc test1.cpp test2.cpp

I get this error:

  Error 1: Previous Definition Different : 
?the_inst ?1??instance ?$singleton Utest    SAXXZ (void cdecl 
singleton<test >::?1??instance::the_inst(void ))

This seems to be something to do with singleton's destructor. If I 
remove it, the example works fine.

Daniel
Sep 22 2005