#### Archived

This topic is now archived and is closed to further replies.

# functionpointer to functions in a class

This topic is 5126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i have the following problem: i have a class CAPARSEROPERATORLIST that represents an unordered single linked list which consist of CAPARSEROPERATOR's. these CAPARSEROPERATOR's hold a function pointer, that should point to one of the functiones defined in CAPARSER, for example OperatorPlus or OperatorDiv. (pseudo code) enum CAPARSEROPERATORTYPE { PLUS, MINUS, TIMES, DIVIDE...} class CAPARSEROPERATOR { CAPARSEROPERATOR* mNext; CAPARSEROPERATORTYPE mType; CAFUNCTIONPOINTER mFunction; }; class CAPARSEROPERATORLIST { CAPARSEROPERATOR* mFirstOperator; insert... delete... }; class CAPARSER { public: CAPARSEROPERATORLIST mOperatorList; public: CABOOL OperatorPlus (CAVALUE,CAVALUE); CABOOL OperatorTimes (CAVALUE,CAVALUE); CABOOL OperatorDiv (CAVALUE,CAVALUE); ... }; so my problem: how do i have to define my functionpointer? i mean CAPARSER must know how CAPARSEROPERATOR is defined, because of mOperatorList. so first i have to define CAPARSEROPERATOR and then CAPARSER. now where my problem is: CAFUNCTIONPOINTER is a pointer which points to a function that is in CAPARSER. so before i can define my functionpointer, i should define CAPARSER. do you see my problem? i tried typedef CABOOL (CAPARSER::*CAFUNCTIONPOINTER) (CAVALUE,CAVALUE); at the top of my code before CAPARSEROPERATOR, but it didn't function, because CAPARSER is unknown at this point... [edited by - kudi on February 7, 2004 10:30:10 AM]

##### Share on other sites
CAPARSEROPERATORLIST only needs to know about the name CAPARSEROPERATOR

so...
class CAPARSEROPERATOR;class CAPARSEROPERATORLIST {     CAPARSEROPERATOR* mFirstOperator;};

Then in your header for CAPARSEROPERATOR you include the CAPARSER header and then have the actual declaration of CAPARSEROPERATOR using the definition of CPARSER and its member functions.

[edited by - petewood on February 7, 2004 10:53:21 AM]