Thread overview | |||||
---|---|---|---|---|---|
|
March 27, 2004 ctor cannot be private? | ||||
---|---|---|---|---|
| ||||
Attachments:
| i cannot understand why i can construct class mike from an outside module. the ctor is made private to turn impossible to construct it... but unexpectdly i can construct it!? why? code example: class mike : Singleton!(mike) { private: this() { printf("this should be impossible to execute from outside\n"); } ~this() { } public: void func() { printf("mike: func\n"); } } thanks, Miguel Ferreira Simões |
March 27, 2004 Re: ctor cannot be private? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Miguel Ferreira Simões | Miguel Ferreira Simões wrote: > i cannot understand why i can construct class mike from an outside module. > the ctor is made private to turn impossible to construct it... but unexpectdly i can construct it!? why? > code example: > class mike : Singleton!(mike) { > private: this() > { > printf("this should be impossible to execute from outside\n"); > } > ~this() > { > } > public: > void func() > { printf("mike: func\n"); > } > } > thanks, > Miguel Ferreira Simões In D a method (or constructor) inherits the same visibility as the method it is overloading and you can't change it. Therefore, I think its got something to do with object's default constructor. Anyway it's a design issue you'll need to take up with Walter. -- -Anderson: http://badmama.com.au/~anderson/ |
March 28, 2004 Re: ctor cannot be private? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson Attachments:
| thanks... for the answer! but that seems a little bit weird, because if all the classes are derived from the Object class and all them have a constructor, that means that it is always possible to construct a class, even if the designer does not want to. are you sure that it works the way you described? walter... join the thread. ps: i want a private constructor!!!! best regards, Miguel Ferreira Simões |
Copyright © 1999-2021 by the D Language Foundation