www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.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