programming2010. 11. 2. 15:27

일반 함수

void main(void)
{
	typedef int(*FUN_POINT_PRINTF)(const char*, ...);

	FUN_POINT_PRINTF _printf = printf;

	_printf("%s world !!!\n", "hello");
	
}

클래스 내에 맴버 함수

class member_func
{
public:
	int func(const char* string)
	{
		return printf(string);
	}
};

void main(void)
{
	typedef int(member_func::*FUN_POINT_PRINTF)(const char*);

	FUN_POINT_PRINTF _func = &member_func::func;

	member_func member_func_obj;
	(member_func_obj.*_func)("hello world !!!\n");
}

함수 포인터를 클래스로 wapper

class wrapper_func
{
	typedef int(*FUN_POINT_PRINTF)(const char*, ...);
public:
	wrapper_func(FUN_POINT_PRINTF func_point_printf) : func_point_printf_(func_point_printf) 
	{}

	int operator() (const char* string)
	{
		return func_point_printf_(string);
	}
private:
	FUN_POINT_PRINTF func_point_printf_;
};

void main(void)
{
	wrapper_func wapper(printf);

	wapper("hello world !!!\n");
}
Posted by 상현달