Trouble using function pointers as parameters.



 DEVELOP > c-Plus-Plus > Trouble using function pointers as parameters.

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER