Newsgroups: comp.lang.c++
Path: utzoo!utgpu!cunews!csi.uottawa.ca!news
From: hitz@csi.uottawa.ca (Martin Hitz)
Subject: Re: G++ question
Message-ID: <1991May7.170521.28054@csi.uottawa.ca>
Keywords: G++, C++
Sender: news@csi.uottawa.ca
Nntp-Posting-Host: sim5
Organization: University of Ottawa
References: <74609@brunix.UUCP> <1991May6.183253.880@husc3.harvard.edu>
Distribution: na
Date: Tue, 7 May 91 17:05:21 GMT

In article <1991May6.183253.880@husc3.harvard.edu> king1@husc10.harvard.edu (Gary King) writes:
> [...] when [g++] gets
>to int ticker::sethandler( void (*f)(int) ) it complains:
>       ticker.cc: 'f' undeclared, outside of functions
>       ticker.cc: parse error before ')'
>
>class ticker {
>public:
>       ticker( int, void (*f) (int) );
>       static int      sethandler( void (*) (int) );
>       // ...
>};
>
>ticker :: ticker( int ticktock, void (*func) (int) ) { /* ... */ }
>
>static int     
>ticker :: sethandler( void (*xll)(int) ) {/* ... */ }

Playing around with your program, I realized that g++ isn't able
to parse the function parameter definition when it appears as the
first parameter [It accepts both, the declaration and the definition of
ticker(), though.  But if you specify a parameter name at the declaration of
sethandler(), the above error message appears already there]. This is
probably a bug, which can be worked around using

typedef void (*fptr) (int);

class ticker {
        // ...
        ticker( int, fptr );
        static int sethandler( fptr );
};
ticker :: ticker( int ticktock, fptr func ) { /*...*/ }

static int ticker :: sethandler( fptr func ) { /*...*/ }
 

Martin Hitz@csi.uottawa.ca
