Newsgroups: comp.lang.c++
Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!lethe!druid!darcy
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: Re: function parameters
Message-ID: <1991May26.031013.1823@druid.uucp>
Organization: D'Arcy Cain Consulting, West Hill, Ontario
References: <2569@m1.cs.man.ac.uk>
Date: Sun, 26 May 91 03:10:13 GMT

In article <2569@m1.cs.man.ac.uk> jk@cs.man.ac.uk (John Kewley ICL) writes:
>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.
Then do it.

>typedef int int_fn( int* );
>int g(const int_fn* fn, int i)
>int f(const int* i)                // CC complains here
This line is actually OK.  you have to change the earlier part:

typedef int int_fn(const int* );
// if you want the function to take a pointer to const then say so

int g(int_fn* fn, const int i)
// the typedef already tells C++ that the function takes a pointer
// to a const int

>line 17: error: bad argument  1 type for g(): int (*)(const int *)
Note that the error suggests the proper typedef.

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   There's no government
Toronto, Ontario, Canada           |   like no government!
+1 416 424 2871                    |
