Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!uw-beaver!milton!sumax!polari!rwing!seaeast!sunbrk!Usenet From: Pete.Becker@sunbrk.FidoNet.Org (Pete Becker) Newsgroups: comp.lang.c++ Subject: Re: function parameters Message-ID: <675518012.71@sunbrk.FidoNet> Date: 28 May 91 23:49:00 GMT Sender: Usenet@sunbrk.FidoNet.Org Lines: 20 In article <2569@m1.cs.man.ac.uk> jk@cs.man.ac.uk (John Kewley ICL) writes: >Why is this, apart from "because the syntax is defined like that", why is >a function with consts on its parameters not valid in place of one with >variable as parameters? A function that takes const parameters promises not to modify those parameters. A function that takes non-const parameters makes no such promise. It is legal to pass either a const or a non-const object to a function that takes a const parameter, because the constness of the object is preserved. It is not legal to pass a const object to a function that takes a non-const parameter, because the function could modify the passed parameter. In this situation, the compiler will create a temporary and pass that as the actual parameter, so the original object will not, in fact, be modified. But when you use a pointer to a function, there's no way for the compiler to know, at the point of the function call, whether to generate that temporary. So the rule on function pointers has to be more strict: the parameter types must agree completely. * Origin: Seaeast - Fidonet<->Usenet Gateway - sunbrk (1:343/15.0)