Skip to main content
gamedev.net
🔒 Locked

Passing pointer to function as parameter

Started by RoTTer Oct 21, 2000 at 4:29 PM 7 replies 550+ views
Original Post
RoTTer
RoTTer
Well, I think thats what Im trying to do :>. But it aint working (of course, or I wouldnt be posting here, lol). I have these functions (not really these but to make it simple) :

int Score (int x, int Level (int));

char Ranking (int player, int Level (int))
{

int points;
points = Score (1000, Level); //****

}

 
But it gives me a "type error in argument 2 to a function : found ''pointer to int function (int)'', expected ''int''" in the line marked with *''s. Im prolly doing something stupid/newbie-like (cause I am, not just bad luck ), so please help me on that =]. The compiler Im using is "LCC", and the language is C, of course :>. Thanks, and cya, -RoTTer
Zipster
Zipster
That was me BTW. Also make sure to put in the integer paramter for Level, which is actually the source to your problem .

Edited by - Zipster on October 21, 2000 5:49:36 PM
RoTTer
RoTTer
Hey

Thanks for the reply =].
But it didnt work =[. Not only I got the same errors but I got a bunch of new errors (when I called the function with "(*Level)(something)" it would give me errors as Level wasnt declared as a function in the header).
But thanks for the try =].

Anyone??? Please :>.

Thanks and cya,
-RoTTer
Zipster
Zipster
Yeah, wow, you post quickly .

Just remember the parameter.

Oh yeah, if you do that, you have to declare the pointer function like so:

int (Level*)(int param); 


Edited by - Zipster on October 21, 2000 5:52:22 PM
RoTTer
RoTTer
Ops, that last reply was to freeman. Lemme try your fix, Zipster. Thanks in advance =]. A couple mins I will post the results.

Cya,
-RoTTer
Zipster
Zipster
MY GOD, im an idiot! The * comes BEFORE the function name, not after!

I feel stupid...
RoTTer
RoTTer
Hey

Well, with the * after or before the function name it didnt work =[. With the * after, I got hundreds of errors, while with the * before the name I got the same eror as before. Lemme post my actual functions here, maybe its something else that is wrong :



double Calcula_Raiz (double a, double b, double erro, double it_max, double (*Funcao_Interseccao)(double), double (*Funcao_Derivada)(double));

double Funcao_12_Tipo_1 (double teta);
double Funcao_12_Tipo_2 (double teta);
double Derivada_12_Tipo_1 (double teta);
double Derivada_12_Tipo_2 (double teta);

void Procura_Raiz_Parte_1 (--tons of crap--)
{

...

teta_raiz = Calcula_Raiz (segmento - TAMANHO_INTERVALO, segmento, epsilon, iteracoes_max, (*Funcao_Interseccao_Tipo_1), (*Funcao_Derivada_Tipo_1));

...

}




Ignore all the crap, just check the last two parameters in this line that starts with "teta_raiz". Those are the parameters that I get that are wrong. Those 4 functions I posted there additionally are the function that after I make this thing work I will send them as parameters. I have about 20 of those small functions, thats why I want to pass them as parameters, to not have to write one big function to each of those 20 small functions I have.


Thanks again and cya,
-RoTTer
RoTTer
RoTTer
Hey

Damn, I finally found the error. Its way too messy to explain, but for me it looked correctly that thing, I still dont know why the compiler wasnt accepting that. Anyway, it doesnt have much to do with the parameters/everything, just a mistake I did (as always ) =].

Thanks for all the help and cya,
-RoTTer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.