On 25/02/2011 15:43, Matthias Kretz wrote:

> I fully understand why it happened. So I imply your answer is that ctors do 
> not have a return value and my expectation, as explained above, is wrong.

  You'd already know if ctors had return values, because you'd have had to be
writing return statements in them all along if they did.  For chapter and
verse, c++ spec (iso/iec 14882) 12.1.10:

> No return type (not even void) shall be specified for a constructor. A 
> return statement in the body of a constructor shall not specify a return
> value. [ ... ]

  No return values there.  (You may have been thinking of overloaded
operators, that often end with a "return *this" statement.)

> The website says:
> "Many functions do not examine any values except their arguments, and have no 
> effects except the return value. Basically this is just slightly more strict 
> class than the pure attribute below, since function is not allowed to read 
> global memory. 
> Note that a function that has pointer arguments and examines the data pointed 
> to must not be declared const. Likewise, a function that calls a non-const 
> function usually must not be const. It does not make sense for a const 
> function to return void."
> 
> All of these statements hold for my ctor in question:
> 1. only examines its arguments
> 2. no effects other than writing to its class members

  So, there you go.  The this object in a constructor is not the "return
value", so writing the members counts as "effects except the return value".
Basically, making your ctor const told the compiler that it would not write to
any of the class object's members!

    cheers,
      DaveK


Reply via email to