Re: exception from constructor
On Aug 2, 10:16 am, Juha Nieminen <nos...@thanks.invalid> wrote:
James Kanze wrote:
No, the proper way of implementing the constructor is, as I
said, to replace the int* with std::vector< int >.
The problem is if std::vector, or any other STL container,
does not do what you want,
Then you create one that does.
and you are creating your own data container.
Then you don't have a second element whose constructor might
throw.
If this is the case, at some point in your code you must
explicitly write the 'new', and you have to be careful that it
doesn't leak in the case of an exception.
There are obviously many cases where you need an explicit new.
That doesn't change anything; whether you use a standard
container, or write some container or smart pointer or whatever
of your own. The point is that any given class can only be
responsible for one resource. The principle of RAII is that the
responsibility for a resource is always in the hands of a single
class whose sole role is to be responsible for that resource.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34