Thread View: comp.lang.c++
2 messages
2 total messages
Started by lear@NET.BIO.NET
Sat, 25 Feb 1989 00:36
passing functions in C++
Author: lear@NET.BIO.NET
Date: Sat, 25 Feb 1989 00:36
Date: Sat, 25 Feb 1989 00:36
17 lines
416 bytes
416 bytes
I wanted arrays that would use strings as their indices. I also wanted a way to apply certain actions to all members of a given array. What I would like to have is something like the following: void MyArray::apply(int (*f)(String,String)) In English, I'd like to pass a pointer to a function. G++ loudly objects to the above definition. Anyone got ideas? Thanks in advance, -- Eliot Lear [lear@net.bio.net]
Re: passing functions in C++
Author: schmidt@glacier.
Date: Sat, 25 Feb 1989 03:55
Date: Sat, 25 Feb 1989 03:55
35 lines
1277 bytes
1277 bytes
In article <Feb.24.16.36.02.1989.14005@NET.BIO.NET> lear@NET.BIO.NET (Eliot Lear) writes: ++ ++ I wanted arrays that would use strings as their indices. I also ++ wanted a way to apply certain actions to all members of a given array. ++ What I would like to have is something like the following: ++ ++ void MyArray::apply(int (*f)(String,String)) ++ ++ In English, I'd like to pass a pointer to a function. G++ loudly ++ objects to the above definition. ++ ++ Anyone got ideas? If you change it to void MyArray::apply(auto int (*f)(String,String)) or use a typedef to declare the type of parameter ``f'' then G++ will have no problems with it. This difficulty is documented in the g++.texinfo file and stems from g++'s use of an LALR(1) grammar to parse the (ambiguous) C++ language. Interestingly enough, cfront 1.2.1 also seems to have the same problem with this particular example (properly expanded to include declaration of class MyArray and type String, of course). Hope this helps! Doug -- schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente. office: (714) 856-4043 | Per me si va nell'eterno dolore. | Per me si va tra la perduta gente. | Lasciate ogni speranza o voi ch'entrate.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads