TITLE: Trying to take the address of constructors PROBLEM: osinski@valis.cs.nyu.edu (Ed Osinski) Right, so it's clear that constructors are a special sort of beast. Member functions are not the same as normal functions, but it was found to be useful to be able to take their addresses, so a special kind of pointer, a pointer to member was invented. Couldn't another kind of pointer, a pointer to constructor, have been invented as well? (I'm not proposing this as a needed change, I'm just suggesting that there seems to be no technical reason for its absence.) RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 14 Jun 95 There are technical reasons why you can't call a ctor via a pointer or take its address. The compiler in general must do extra things with ctors, and the way they are called depends on the details of the implementation, and not just on the language definition. Simplest example: class VB { public: VB(int); }; class D : public virtual VB { public: D(int); }; class E : public D { public: E(int); }; Each class has exactly one ctor, taking an int parameter. If we construct a D object, the ctor invokes the VB ctor via its member-init list. If we construct an E object, the ctor invokes the VB ctor via its member-init list, then the D ctor. But this time the D ctor must NOT invoke the VB ctor, since the VB part has already been constructed. Somehow the one ctor for D must be told whether to invoke the VB ctor. This can be done by passing an extra parameter. It can also be done by "splitting" the ctor: making two different ctors, and calling one or the other depending on whether the D object is the complete object or not. Dtors have exactly the same problem with virtual base classes -- only the dtor of the complete object invokes the VB dtor. There are other special considerations with ctors and dtors which I won't go into here, since they are along similar lines. There would be no way to write code that depended on hidden implementation details which vary from compiler to compiler, and for one compiler might need to change from release to release, so the language definition just says you can't do it.