D - ctor cannot be private?
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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:=20
this()
{
printf("this should be impossible to execute from outside\n");
}
~this()
{
}
public:
void func()
{=20
printf("mike: func\n");
}
}
thanks,
Miguel Ferreira Sim=F5es
Mar 27 2004
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/
Mar 27 2004
Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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=20 does not want to. are you sure that it works the way you described? = walter... join the thread.=20 ps: i want a private constructor!!!! best regards, Miguel Ferreira Sim=F5es
Mar 28 2004








=?iso-8859-1?Q?Miguel_Ferreira_Sim=F5es?= <kobold netcabo.pt>