| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Thomas Nelson" |
| Date: |
09 Apr 2007 12:08:21 PM |
| Object: |
Trouble using function pointers as parameters. |
I'm trying to write a function that uses function pointers. Here's my
errors:
Board.cc:111: error: expected ',' or '...' before 'p1'
Board.cc:111: error: prototype for 'int Board::play_game(int (*)(const
Board&))' does not match any in class 'Board'
Board.h:18: error: candidate is: int Board::play_game(int (*)(const
Board&), int (*)(const Board&), bool)
Here's Board.cc:111:
int Board::play_game(int(const Board &) p1, int(const Board &) p2,
bool silent=false)
And here's Board.h:18:
int play_game(int(const Board &), int(const Board &), bool
silent);
What have I done wrong? I wanted to use a typedef to simplify this,
but Board has to be declared to use it in a typedef, and I want to use
the typedef in my Board declaration. Any help would be great.
Thanks,
Tom
.
|
|
| User: "Jonas" |
|
| Title: Re: Trouble using function pointers as parameters. |
09 Apr 2007 01:29:05 PM |
|
|
"Thomas Nelson" <thn@mail.utexas.edu> wrote in message
news:1176138501.837226.283740@y80g2000hsf.googlegroups.com...
I'm trying to write a function that uses function pointers. Here's my
errors:
Board.cc:111: error: expected ',' or '...' before 'p1'
Board.cc:111: error: prototype for 'int Board::play_game(int (*)(const
Board&))' does not match any in class 'Board'
Board.h:18: error: candidate is: int Board::play_game(int (*)(const
Board&), int (*)(const Board&), bool)
Here's Board.cc:111:
int Board::play_game(int(const Board &) p1, int(const Board &) p2,
bool silent=false)
And here's Board.h:18:
int play_game(int(const Board &), int(const Board &), bool
silent);
What have I done wrong? I wanted to use a typedef to simplify this,
but Board has to be declared to use it in a typedef, and I want to use
the typedef in my Board declaration. Any help would be great.
Like so:
int Board::play_game(int (*p1)(const Board &), int (*p2)(const Board &),
bool silent=false);
Or, using a typedef:
class Board {
typedef int func(const Board & board);
int play_game(func * p1, func * p2, bool silent=false);
};
Alternatively,
class Board;
typedef int func(const Board & board);
class Board {
int play_game(func * p1, func * p2, bool silent=false);
};
--
Jonas
.
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Trouble using function pointers as parameters. |
09 Apr 2007 12:11:56 PM |
|
|
Thomas Nelson wrote:
I'm trying to write a function that uses function pointers. Here's my
errors:
Board.cc:111: error: expected ',' or '...' before 'p1'
Board.cc:111: error: prototype for 'int Board::play_game(int (*)(const
Board&))' does not match any in class 'Board'
Board.h:18: error: candidate is: int Board::play_game(int (*)(const
Board&), int (*)(const Board&), bool)
Here's Board.cc:111:
int Board::play_game(int(const Board &) p1, int(const Board &) p2,
bool silent=false)
And here's Board.h:18:
int play_game(int(const Board &), int(const Board &), bool
silent);
What have I done wrong? I wanted to use a typedef to simplify this,
but Board has to be declared to use it in a typedef, and I want to use
the typedef in my Board declaration. Any help would be great.
Read the FAQ 5.8. That's for the next time. For now, however, try
changing it to
/* in header */
int play_game(int (*)(const Board&), int (*)(const Board&),
bool = false);
/* in TU */
int play_game(int (*p1)(const Board&), int (*p2)(const Board&),
bool silent /* = false */)
{
return 42;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
|
|
|
| User: "Thomas Nelson" |
|
| Title: Re: Trouble using function pointers as parameters. |
09 Apr 2007 12:42:54 PM |
|
|
On Apr 9, 12:11 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Thomas Nelson wrote:
I'm trying to write a function that uses function pointers. Here's my
errors:
Board.cc:111: error: expected ',' or '...' before 'p1'
Board.cc:111: error: prototype for 'int Board::play_game(int (*)(const
Board&))' does not match any in class 'Board'
Board.h:18: error: candidate is: int Board::play_game(int (*)(const
Board&), int (*)(const Board&), bool)
Here's Board.cc:111:
int Board::play_game(int(const Board &) p1, int(const Board &) p2,
bool silent=false)
And here's Board.h:18:
int play_game(int(const Board &), int(const Board &), bool
silent);
What have I done wrong? I wanted to use a typedef to simplify this,
but Board has to be declared to use it in a typedef, and I want to use
the typedef in my Board declaration. Any help would be great.
Read the FAQ 5.8. That's for the next time. For now, however, try
changing it to
/* in header */
int play_game(int (*)(const Board&), int (*)(const Board&),
bool = false);
/* in TU */
int play_game(int (*p1)(const Board&), int (*p2)(const Board&),
bool silent /* = false */)
{
return 42;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks, this fixed my problem. Next time I will post more descriptive
code.
Tom
.
|
|
|
|
|

|
Related Articles |
|
|