Thread: [Dev-C++] Pointer to function
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Harry P. <wi...@ma...> - 2004-07-03 18:44:49
|
Hello, All!!!
I need to call function-member of class by its pointer. For example:
//- main.h ----------------------------------
#include <iostream>
#include <stdlib.h>
class A
{
public:
int f (void) { return 5; }
};
//- main.cpp --------------------------------
#include "main.h"
using namespace std;
int main(int argc, char *argv[])
{
A cA;
int ( A::*pFunc ) (void);
pFunc = &A::f;
// cout << ??? How I can call cA.f() using the pointer pFunc?
system("PAUSE");
return 0;
}
|
|
From: David M. <dml...@co...> - 2004-07-04 03:22:51
|
int result3 = (instance.*pt2Member)(12, 'a', 'b'); // Outside class int result4 = (*this.*pt2Member)(12, 'a', 'b'); // Inside class in your case it would be: cout << (cA.*pFunc)(); A good tutorial on this topic is avalible @ www.function-pointer.org Hope this Helps David McKen Harry Piterson wrote: > Hello, All!!! > > I need to call function-member of class by its pointer. For example: > > > //- main.h ---------------------------------- > #include <iostream> > #include <stdlib.h> > > class A > { > public: > int f (void) { return 5; } > }; > > //- main.cpp -------------------------------- > #include "main.h" > > using namespace std; > > int main(int argc, char *argv[]) > { > A cA; > > int ( A::*pFunc ) (void); > > pFunc = &A::f; > > // cout << ??? How I can call cA.f() using the pointer pFunc? > > system("PAUSE"); > return 0; > } > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Harry P. <wi...@ma...> - 2004-07-08 14:54:59
|
Hello David, Sunday, July 4, 2004, 7:22:29 AM, you wrote: DM> int result3 = (instance.*pt2Member)(12, 'a', 'b'); // Outside class DM> int result4 = (*this.*pt2Member)(12, 'a', 'b'); // Inside class Thank you for the documentation!!! It's all that I really need. -- Best regards, Harry mailto:wi...@ma... |
|
From: Alvin T. <al...@th...> - 2004-07-06 15:24:03
|
if you're using c++ you may want to use virtual functions/polymorphism
instead of using function pointers...
-alvin
Harry Piterson wrote:
> Hello, All!!!
>
> I need to call function-member of class by its pointer. For example:
>
>
> //- main.h ----------------------------------
> #include <iostream>
> #include <stdlib.h>
>
> class A
> {
> public:
> int f (void) { return 5; }
> };
>
> //- main.cpp --------------------------------
> #include "main.h"
>
> using namespace std;
>
> int main(int argc, char *argv[])
> {
> A cA;
>
> int ( A::*pFunc ) (void);
>
> pFunc = &A::f;
>
> // cout << ??? How I can call cA.f() using the pointer pFunc?
>
> system("PAUSE");
> return 0;
> }
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
Alvin Thompson
Navy: 34
Army: 6
|
|
From: Harry P. <wi...@ma...> - 2004-07-08 14:55:00
|
Hello Alvin, It's really slow... My application is critical to run time. I use thread to handle events and change programm's state. Tuesday, July 6, 2004, 7:23:47 PM, you wrote: AT> if you're using c++ you may want to use virtual functions/polymorphism AT> instead of using function pointers... AT> -alvin -- Best regards, Harry mailto:wi...@ma... |
|
From: Per W. <pw...@ia...> - 2004-07-08 15:51:43
|
Since the speed difference of a function pointer compared to a virtual method call is less than a nanosecond on a modern computer - in some cases the speed difference is zero because of specific c++ code optimizations in the compiler - you have a major problem if you think virtual method calls aren't fast enough... /Per W On Thu, 8 Jul 2004, Harry Piterson wrote: > Hello Alvin, > > It's really slow... My application is critical to run time. I use > thread to handle events and change programm's state. > > Tuesday, July 6, 2004, 7:23:47 PM, you wrote: > > AT> if you're using c++ you may want to use virtual functions/polymorphism > AT> instead of using function pointers... > > AT> -alvin > > -- > Best regards, > Harry mailto:wi...@ma... > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |