|
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 |
digitalmars.D - How to make a singleton?
I tried to make a singleton for some particular class. As in C++ I made
constructor of this class protected, made method for instance access and so on.
All works fine until I try to instanciate my class outside the module where it
is defined. I was surprised but I didn't get any compile error after this trick.
How to prevent construction of class outside any module other then class owner?
Kernel kernel;
static this()
{
kernel = new Kernel;
}
class Kernel
{
protected:
this()
{
hInstance = GetModuleHandleA(null);
}
public:
.....
}
// another module snipet
int main ( char [] [] args )
{
Kernel k = new Kernel; // no error!
kernel.runMainLoop();
return 0;
}
Is it normaly?
----
nail
Nov 19 2004
nail wrote:I tried to make a singleton for some particular class. As in C++ I made constructor of this class protected, made method for instance access and so on. All works fine until I try to instanciate my class outside the module where it is defined. I was surprised but I didn't get any compile error after this trick. How to prevent construction of class outside any module other then class owner? Nov 19 2004
|