Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 12th, 2006, 6:28 AM   #1
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3 Jimbo is on a distinguished road
Function pointer to a member function

I'm writing Chess in what little free time I have these days, and I'm currently working on getting the pieces to calculate their possible moves. My specific problem is with pawns, which can only move in a single direction, determined by where they started (i.e. by color). Anyways, I'm trying to create a forward pointer that will get the square "in front" of where the pawn is now.

I have the line in pawn.cpp:
Square (*fwd)() = (getColor() == White) ? &Square::up : &Square::down;
where Square::up() and Square::down() are public functions declared in square.h as
public: /* ... */
     Square* up();
     Square* down();
The error I get is:
Quote:
pawn.cpp:16: error: cannot convert `Square*(Square:)()' to `Square (*)()' in initialization
Is there a good way to get this to work? For that matter, what exactly does this error message mean? I'm thinking that it's complaining about making a pointer to a function specifically inside the Square class. Should I perhaps rethink how I'm doing this?

BTW, I'm compiling using g++ and running Linux, not that it should matter for this...
Jimbo is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC