Ending a program from within the constructor
Posted on 2004-03-27
I'm pretty new to C++ so this may prove to be a simple question. I have class hierarchy that is used to illustrate PC's and their components, with the base class I'm working with being the PC. I have done some validation in the construtor using a dynamic_cast to down cast the CPU entered by the user to a derived class. If the cast fails then the PC can not be fitted to this kind of PC. This all works fine but I would really like to end the program there and then from within the constructor. At the moment all I do is cout a message saying there has been an error. Is it possible to do something in here? I tried immediatly calling the destructor from within the constructor but that failed.
Any help at all will be a god-send.