English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

can some on explain and give me some example

2006-06-15 11:01:04 · 4 answers · asked by cold gold 1 in Computers & Internet Programming & Design

4 answers

To pass a function as argument you will need to get address of that function. As C++ allows function overloading this is slightly different from C. Look the following example
Suppose we have a function with two overloaded version,
int sum(int i, int j)
int sum(int i,int j, int k)
To get address of second function
int (*f) (int , int , int);
f=sum;

Now this pointer can be passed to a function.


Passing function as argument is no longer necessary practice, neither recommended. C++ includes it as legacy of C. This were needed in C because C was not object oriented. Now in C++ you can achieve same result easily and clearly using objects.

2006-06-15 15:28:21 · answer #1 · answered by Tanaeem 4 · 2 0

Need more information. Are you asking about arguments passed to a function, or passing a function *as* an argument to another function? Or something else?

2006-06-15 12:01:14 · answer #2 · answered by Flyboy 6 · 0 0

a million. regardless of the undeniable incontrovertible truth that the language wasn't outfitted with this in ideas, it form of feels that different, that is plausible. even if, it comes with the project that each and each and anyone applications which will ever be exceeded as a given argument might want to themselves percentage the similar argument list and the similar go back form. that's likewise plausible to create arrays of applications using a similar body of ideas. 2. As I keep in concepts, the syntax is a few thing like this. allow's say I have the following 2 (ineffective, yet short) applications: int asdf(int i) { go back (i+a million); } int qwer(int i) { go back (i-a million); } and the following function taking a function as a parameter: int zxcv(int i,int (*p)(int)) { go back p(i); } then if I ran this code: cout<

2016-11-14 20:06:32 · answer #3 · answered by Anonymous · 0 0

class call_function
{
private :
int a;
int b;
int c;
public :
add_function(int i, int j);
}
void call_function::add_function(int i,int j)
{
c := i + j
}
void main()
{
int x;
int y;
call_function f1;
cin>>x;
cin>>y;
cout< }

2006-06-15 21:28:25 · answer #4 · answered by Suresh k 1 · 0 0

fedest.com, questions and answers