Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!mucs!jk From: jk@cs.man.ac.uk (John Kewley ICL) Newsgroups: comp.lang.c++ Subject: function parameters Message-ID: <2569@m1.cs.man.ac.uk> Date: 24 May 91 13:24:19 GMT Sender: news@cs.man.ac.uk Reply-To: jk@cs.man.ac.uk (John Kewley ICL) Organization: Department of Computer Science, University of Manchester UK Lines: 39 The following program is supposed to print 81, the square of 9. Unfortunately I would prefer to use a function which takes a constant int pointer as a parameter to pass to g rather than a variable one. This program fails to compile because of the const on the line labelled below. //--------------------------------------------------------- #include typedef int int_fn( int* ); int g(const int_fn* fn, int i) { return(fn(&i)); } int f(const int* i) // CC complains here { return( *i**i ); } int main() { printf( "i=%d\n",g(f,9) ); return(0); } //--------------------------------------------------------- Error message: line 17: error: bad argument 1 type for g(): int (*)(const int *) ( int (*)(int *) expected) //--------------------------------------------------------- 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? -- J.K. John M. Kewley, ICL, Wenlock Way, West Gorton, Manchester. M12 5DR Tel: (+44) 61 223 1301 X2138 Email: jk@cs.man.ac.uk / jk@nw.stl.stc.co.uk