TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 29 June 2020

Find The Address Of An Overloaded Function In C++| Find The Address Of An Overloaded Function In C++ In Hindi

Find The Address Of An Overloaded Function In C++

You can obtain the address of a function. One reason to do so is to assign the address of the function to a pointer and then call the function through that pointer. If the function not overloaded this process is straightforward, for overloaded function the process requires a little more subtlety. To understanding the first consider this statement which assigns the address of some function called myfunc() to pointer called p:

p=myfunc;

If myfunc() is not overloaded there is one and only one function called myfunc(),and the compiler has no difficulty assigning its address to p.

 

image of Find The Address Of An Overloaded Function In C++
Fig: Find The Address Of An Overloaded Function In C++

Program:

#include<iostream.h>

class BCA;

int myfunc(int a);

int func(int a, int b);

int main()

{

int (*fp) (int a);

fp=myfunc;

cout<<”fp(5);

return 0;

}

int myfunc(int a)

{

return a;

}

int myfunc(int a,int b)

{

return a*b;

}

 

Here , there are two type version of myfunc(). Both return int, but take a single integer argument; the other requires two integer aruguments. In the program, fp is declared as a pointer to a function the return an integer and that take one integer argument. When fp is assigned the address of myfunc(), c++ uses this information to select that myfunc(int a) version of myfunc(). Had fp been declared like this:

int (*fp) (int a, int b);


No comments:

Post a Comment