Weird (?) problem
Ary Manzana
asterite at gmail.com
Thu Aug 10 07:41:20 PDT 2006
mike wrote:
> Thanks, it works! :-)
>
> I still need one little workaround, but that's ok.
>
> Funny thing is: Thinking about it a little bit more I got that idea:
>
> ' class TypeFoo : TypeBase
> ' {
> ' public:
> ' static this() { instance = new Bar(); }
> '
> ' private:
> ' void setup() { /* add object, setup */ }
> ' TypeBase instance;
> '
> ' unittest
> ' {
> ' instance.setup();
> ' }
> ' }
>
> since the unittest will be executed after ALL static this()'s are done,
> and it's the only piece of code that is tied to a class and called
> automatically (besides the constructors) - but I don't want to be that
> evil :-)
Watch out!! Unit tests are only for debug purposes, once you compile
your code with the "release" flag, no unit test will ever be invoked.
>
> Another question:
>
> Is there a way to prevent a derived class from calling super()? I solved
> this currently with an empty this(int) and calling super(0), but is
> there another way?
I believe not, and it's because of the OOP philosophy... But you can
always make a protected constructor for your derived classes, although
this increases code dependency between classes, and I don't recommend it.
>
> -Mike
>
>
> Am 10.08.2006, 14:14 Uhr, schrieb Ary Manzana <asterite at gmail.com>:
>
>> Have you tried placing code after "instance = new TypeType()"?
>>
>> Like this:
>>
>> ' class TypeType : TypeBase
>> ' {
>> ' TypeBase instance = null;
>> ' static this() {
>> ' instance = new TypeType();
>> ' // I don't know whether addObject is a function
>> ' // or a member of TypeType, but you get the point
>> ' instance.addObject("typetype");
>> ' instance.getObject("typetype").setType(instance);
>> ' }
>> ' static TypeBase opCall() { return instance; }
>> ' this()
>> ' {
>> ' }
>> ' }
>>
>> Hope that helps (and works).
>> Ary
>
>
>
> --Erstellt mit Operas revolutionärem E-Mail-Modul:
> http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list