opMul

Simen Kjaeraas simen.kjaras at gmail.com
Mon Mar 3 06:08:55 PST 2008


On Mon, 03 Mar 2008 04:10:36 +0100, Denton Cockburn <diboss at hotmail.com>  
wrote:
> A function does not have to be constant to allow a constant parameter.
> It just has to promise not to change the parameter.

And that is exactly what const does.

> I don't understand why opMul would change the parameter, or more
> importantly, why it can't be stated that it WONT change the parameter in
> any cases.

Given

struct Foo
{
	int bar;
	void doStuff(Foo b)
	{
		bar += b.bar;
	}
}

would you expect

const Foo f,g;
f.doStuff(g);

to work without problems? This is exactly the same, only doStuff is not  
considered special by the compiler.

You might argue that the compiler should enforce opMul, opDiv, etc. to be  
const, but that does carry a load of other troubles with it.

> I think this is related to what Janice spoke about.  The constant changes
> that have taken place need to be properly incorporated into the language
> and library.  There are a lot of places where constant doesn't work as
> would be intuitively expected.

This is intuitive to me. (Well, apart from what I mentioned in the  
response to Bill :p)



More information about the Digitalmars-d mailing list