aw1r+@andrew.cmu.edu (Alfred Benjamin Woodard) (07/24/90)
I am having trouble getting my week class to compile. Assume that all other things are taken care of in other parts of the source code. The problem is that the compiler complains that there are syntax errors in all the function definitions for the week class. void poptokens(int (*oktopop) (short,token*) ); //pop all the tokens for the class void inserttokens (int (*oktoinsert) (short,tlist) , int try); //insert the tokens that are ok to insert but yet when I do this earlier in the source code when I define the slot class it works fine. void poptoken(char slotnum, tlist *pool,int (*function)(short, token* )); //pops the tokens from the slots and puts them in the pool for the life of me I cannot see what the difference is and why the compiler complains. What I am really trying to do is just pass the function pointer through poptokens to poptoken because the consumer will not see the poptoken function. If you need to see any more of the source let me know. Below is the actual code in which these two cases occur. thank you very much -ben aw1r+@andrew.cmu.edu /************* * slot class * *************/ class slot: public tlist { public: void poptoken(char slotnum, tlist *pool,int (*function) (short, token* )); //pops the tokens from the slots and puts them in the pool }; void slot::poptoken(char slotnum, tlist *pool,int (*function)(short,token* ) ){ int num=tlist::number(); //keeps a costant value of the number of tokens that were in the list for (int I=0; I<num; I++) //iterates through all of the tokens if ( ( *function ) (slotnum, tlist::advance() ) ) { //if the fuction called says it is a good idea to pop then it will pool->add(tlist::current()); //add it to the specified pool tlist::del(tlist::current()); //delete it from the other slot tlist::backup(); //move back one so the new current element gets looked at } } /************* * week class * *************/ class week { slot slots[42]; tlist pool; public: void poptokens(int (*oktopop) (short,token*) ); //pop all the tokens for the class void inserttokens (int (*oktoinsert) (short,tlist) , int try); //insert the tokens that are ok to insert }; void week::poptokens(int (*oktopop) (short,token*) ){ for (short I=0; I<43; I++) //iterate through all of the tokens slots[I].poptoken(I,&pool, oktopop ); //pop the ones that should be popped } void week::inserttokens (int (*oktoinsert) (short,tlist) ,int try){ num=pool.number(); //keep a constan of the number of tokens that were in the pool for (int token=0; token<num; token++) //iterate through all of the tokens in the pool. while (try>0) { //iterate through the number of tries. slotnum=rand(42); //generate the random value of the token if ( (*oktoinsert)(slotnum,pool.advance()) ) { //if it is ok to insert then do so. slots[slotnum].add(pool.current()); //add it to the slot that said it was ok pool.del(pool.current()); //delete it from the pool pool.backup(); //move back in the list so that the current element gets accesed. } } } -ben