TITLE: Determining constructors at run-time PROBLEM: andy@comp.lancs.ac.uk (Andy Colebourne) Is it possible to pass constructors as function pointers, so that objects may be created later by calling the pointers? RESPONSE: adk@Warren.MENTORG.COM (Ajay Kamdar), 30 Mar 93 It is not legal to take the address of a constructor, and hence pointers to constructors cannot be passed around directly. However, one way to do what you want is to create static helper functions which create a new object and return it. Pointers to these static functions can then be used when new objects are required. class A { public: A(); // cannot take the address of this constructor directly static A* createA(); // This functions create a new A object on the heap and // returns a pointer to it. // // A pointer to this function can be passed in lieu of a // a pointer to the constructor. }; [ This method would work very well with designs which put only abstract classes in .h files (a good way to control unnecessary rebuilds). This leaves open only the question of how to do a "new", since the exact type must be visible. The above static function can be used to wrap up and hide the subtypes. -adc ]