Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!borland.com!pete From: pete@borland.com (Pete Becker) Newsgroups: comp.lang.c++ Subject: Re: function parameters Message-ID: <1991May28.184900.3692@borland.com> Date: 28 May 91 18:49:00 GMT References: <2569@m1.cs.man.ac.uk> Organization: Borland International Lines: 17 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.