Reputation: 45
I have a situation where a function can only take "int" (can't change this) and I need it in a different situation. let me directly write the code
bool foo(int dev)
{
...
...
return true/false;
}
I need to pass :
mClassPointer->dev()
mClassPointer[index]->dev()
dev() //(function)
dev //(variable)
mClassPointer
is pointer to class.
dev()
is a member function of a class , return an Integer.
Upvotes: 0
Views: 106
Reputation: 7631
You may be able to do that by changing the argument to a void*.
Be very careful with this and read this thread carefully, espc. the post by Loki Astari:
error: cast from 'void*' to 'int' loses precision
If the function only accepts an int then I don't know if this is possible. Read a discussion in this thread if you are thinking of casting your pointers to int and passing. May not work on certain platforms: Converting a pointer into an integer
Upvotes: 1
Reputation: 2590
If you have a function that needs to handle different datatypes in different situations (as is vaguely implied in your question), then perhaps you need to look into templates.
Upvotes: 1