Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Greg K


This topic is 6159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include "iostream.h"

class MyClass
	int t;
	void MyFunc( void ){ cout << "HI"; }

void main( void )
	void (MyClass:: *pFunc)( void );
	pFunc = MyClass::MyFunc;
First of all, what does this do. Second of all, how do I make a pointer to the MyFunc funtion? Thanks.

Share this post

Link to post
Share on other sites
that code really doesn''t do anything. pointers to class functions (also called "methods") are rarely used and ugly, i dont know why. only static methods can be called without an object, so you can''t do anything with that fuction unless you create an instance of the class.


Share this post

Link to post
Share on other sites
not totally true there is an operator to call a member function of an object :


class A
void Test();


typedef void (A::*A_FUNCTION(void));

A a;

A* aPtr;

A_FUNCTION func = &A::Test;

//calling with instance see the little . before the *


//calling with a pointer


Now that was ugly!!!! But he C++ standard provides with a nice object to hide all the uglyness, it is called mem_funt_t

the next piece of code does exactly has above


#include <functionnal>

std::mem_fun_t function( &A::Test );

A a;


mem_fun_t is very usefull for doing callbacks to objects.

Edited by - Gorg on February 5, 2002 2:14:56 AM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!