[comp.lang.c++] Functions taking function parameters

orr@cs.glasgow.ac.uk (Fraser Orr) (06/10/88)

Sorry if this is a simple question with an obvious answer, but can anybody tell
me the type of a function taking a function as paramter.
For example, say I have a list class, and I want to have a member function that
performs some function on all the elements of the list ...

class List {
	SomeType Data [ SomeSize ] ;
public:
	.
	.
	.
	void Iterator ( void fn ( SomeType ) ) ;
end ;

the line `void Iterator ( void fn ( SomeType ) ) ;' gives a syntax error.

Any ideas?

==Fraser Orr ( Dept C.S., Univ. Glasgow, Glasgow, G12 8QQ, UK)
UseNet: {uk}!cs.glasgow.ac.uk!orr       JANET: orr@uk.ac.glasgow.cs
ARPANet(preferred xAtlantic): orr%cs.glasgow.ac.uk@nss.cs.ucl.ac.uk

ark@alice.UUCP (06/12/88)

In article <1340@crete.cs.glasgow.ac.uk>, orr@glasgow.UUCP writes:
 
> class List {
> 	SomeType Data [ SomeSize ] ;
> public:
> 	.
> 	.
> 	.
> 	void Iterator ( void fn ( SomeType ) ) ;
> end ;
> 
> the line `void Iterator ( void fn ( SomeType ) ) ;' gives a syntax error.

First of all, I presume you meant to say

	};

instead of

	end;

Either that or you have some nasty preprocessor macros.

Anyway, your problem is a long standing bug in cfront.
This bug is extremely hard to fix.  Nevertheless, I believe
it will be fixed in a future release of cfront.

THe way to circumvent it is to use typedef:

	typedef void void_func_SomeType (SomeType);

	// . . .

	void iterator (void_func_sometype* fn);

Don't forget the * -- you can't pass functions as arguments,
only pointers to functions.