Group: comp.lang.c++
From: James Kanze
Date: Saturday, February 16, 2008 2:56 PM
Subject: Re: Why do constructors have same name as the class ?

On Feb 16, 3:53 pm, yeti wrote:
> On Feb 16, 3:21 am, Andre Kostur wrote:> yeti .k...@gmail.com> wrote in news:951bda7f-23be-426e-b0f3-
> > 4c37d8fe4...@d4g2000prg.googlegroups.com:

> > > 2. Why can't constructor and destructor return values ??

> > Return values to where? What's your use-case for having
> > these return values?

> If constructors could return values they could possibly return error
> codes if object construction failed.

A constructor establishes the class invariants. If it fails,
the class invariants can't be established. Which means that the
instance of the class shouldn't exist.

In sum, what we get with exceptions.

--
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

Safety Articles | Usenet Groups | Usenet News | Bluegrass