Re: [Dev-C++] Re: Design decision in C++
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-03-11 16:30:40
|
I haven't looked at any Singleton<DataType> class doing any instance pointer offset hack. The sample code I sent for a singleton object was just a very fiew lines of manually added code to the class in question. 100% valid C++ without any typecasts. /Per W On Thu, 11 Mar 2004, Doug MacDonald wrote: > Per and Kevin, > > Thanks for your advice. > > My ambivalence wrt the Singleton<DataType> class is in part due to the > instance pointer offset hack, which seems to introduce a risk of > implementation dependency: are base and derived classes always included > in a standard order with offsets that never vary from compiler to > compiler?. Further, the instance pointer adjustment involves pointer > <-> int casts that are a bit ugly, despite the elegance of Singleton as > seen from the outside. > > But I take your points as to the limited desirability of fully static > classes. > > (I guess declaring a top-level static _instance_ of a class is a > different matter, and is useful, e.g., when there is no C++ main > routine, as was the case in a former project of mine at my last employer.) > > --Doug > > > > |