|
Archives
D Programming
DD.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++ - fatal bug: cannot link static singleton class
This fails to link (dmc m1.cpp m2.cpp):
m1.cpp:
#include "single.h"
int main() { X::instance(); }
m2.cpp:
#include "single.h"
void f() { X::instance(); }
single.h
struct X {
static void instance() { static X x; }
X() {} // comment out the ctor to link successfully
};
The error is:
link m1+m2,,,user32+kernel32/noi;
OPTLINK (R) for Win32 Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
m2.obj(m2) Offset 0011AH Record Type 0091
Error 1: Previous Definition Different : ?x ?1??instance X SAXXZ (void cdecl
X::?1??inst
ance::x(void ))
--- errorlevel 1
Thanks,
Sz.
Nov 04 2003
This one may be sort of important. I hope I'm wrong, but I found the static singleton idiom as the only solution for some cases (like a header-only implementation of a debug output controller, or default allocator instances), and I had to temporarily drop DMC support for our lib due to the problem below. Any ideas for workaround? Can I still use some kind of a "persistent" class instance (living while the process lives; i.e. some static) without adding a .cpp and losing portability? Cheers, Sz. "Luna Kid" <lunakid neuropolis.org> wrote in message news:bo9lvq$mj9$1 digitaldaemon.com... Nov 07 2003
Have you tried the latest beta DMC++? "Luna Kid" <lunakid neuropolis.org> wrote in message news:bog3ar$11jv$1 digitaldaemon.com...This one may be sort of important. I hope I'm wrong, but I found the static singleton idiom as the only solution for some cases (like a header-only implementation of a debug output controller, or default allocator instances), and I had to temporarily drop DMC support for our lib due to the problem below. Any ideas for workaround? Can I still use some kind of a "persistent" class instance (living while the process lives; i.e. some static) without adding a .cpp and losing portability? Cheers, Sz. "Luna Kid" <lunakid neuropolis.org> wrote in message Nov 07 2003
Yes (after you suggested...). Same thing. Thanks, Sz. "Walter" <walter digitalmars.com> wrote in message news:bogmhh$1sf7$1 digitaldaemon.com...Have you tried the latest beta DMC++? "Luna Kid" <lunakid neuropolis.org> wrote in message news:bog3ar$11jv$1 digitaldaemon.com...This one may be sort of important. I hope I'm wrong, but I found the static singleton idiom as the only solution for some cases (like a header-only implementation of a debug output controller, or default allocator instances), and I had to temporarily drop DMC support for our lib due to the problem below. Any ideas for workaround? Can I still use some kind of a "persistent" class instance (living while the process lives; i.e. some static) without adding a .cpp and losing portability? Cheers, Sz. "Luna Kid" <lunakid neuropolis.org> wrote in message Nov 07 2003
|