-
April 4th, 2013, 10:27 AM
#1
how to properly use a function pointer to a particular function
#include <iostream>
using namespace std;
int function(int a,int b)
{
return a + b;
}
bool function2(int a,int b)
{
return a < b;
}
void function3(int c, int(*cmp)(int a,int b) )
{
bool (*compare)(int,int) = &function2;
if( (*compare)(c,(*cmp)(a,b)))
{
cout << " this number is way bigger then the two " <<endl;
}else{
cout << " this number is lower " <<endl;
}
}
int main(int argc,char *argv[])
{
int (*foo)(int,int) = &function;
int a = 5, b = 10;
int sum = (*foo)(a,b);
cout << " the sum of two values: " << sum <<endl;
bool (*foo2)(int,int) = &function2;
if((*foo2)(a,b))
{
cout << " this is the power of c " <<endl;
}else {
cout << " this is not the power of c " <<endl;
}
system("pause");
return EXIT_SUCCESS;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|