C++ function and local char with same name

Okay, so I ran into a problem while making a header that has the following function declarations:

1
2
int find(char *find, char *where);
int replace(char *find, char *where, char *replace);


Now when in replace, if I try this line:

 
find(find, where);//Take find from the char sent by replace and continue it on 


I get the error: error C2064: term does not evaluate to a function taking 2 arguments

So it thinks I'm calling find() while I'm calling char *find. Now obviously, I can resolve this by just changing the name. Tried it and it worked.

But I'm curious, is there a way to tell the compiler that I want to use char *find rather then int find()?

Thanks
Last edited on
The scope operator.

 
::find(find,where);
Can you kinda explain how that works? I thought the scope operator needed something before it?

(Note that it does work)
int find() (the function) has global scope
char* find (the variable) has local scope (local to replace)

The compiler will use the variable with the shortest scope in such instances. Here, because the variable has local scope, it is used by default.

Using the scope operator with nothing before it tells the compiler to look in global scope.

1
2
::find;  // compiler looks for a global 'find', it uses the function
find;  // compiler looks for the shortest scope 'find', it uses the variable 
Ahh, okay! Thanks!!
Topic archived. No new replies allowed.