1. 程式人生 > >c++高能指針

c++高能指針

c++

#include<iostream>
using namespace std;
void add(int i, int j)
{
	cout << "add" << i + j << endl;
}


class func
{
public:
	void jian(int i, int j)
	{
		cout << "jian" << i - j << endl;
	}
};


int main()
{
	void(*p)(int, int) = add;
	p(2, 3);//add5
	(*p)(3, 4);//add7
	(**************************p)(3, 4);//add7
	(*&p)(3, 7);//add10
	cout << (void*)p << "   " << (void*)(*p) << endl;                                      //00CA1334   00CA1334
	cout << typeid(p).name() << endl;                                                      //void(__cdecl*)(int, int)
	cout<< typeid(*p).name() << endl;                                                      //void __cdecl(int, int)
	cout << typeid(******************p).name() << endl;                                    //void __cdecl(int, int)
	cout << "   " << typeid(&p).name() << endl;                                            //void(__cdecl**)(int, int)
	cout<< typeid(*&p).name() << endl;//void(__cdecl*)(int, int)
	cout << "#####################################" << endl;
	auto fun1 = &func::jian;
	cout << typeid(fun1).name() << endl;//void(__thiscall func::*)(int, int)
	void(func::*func2)(int, int) = &func::jian;//void(__thiscall func::*)(int, int)
	cout << typeid(func2).name() << endl;

	func funcc;
	(funcc.*func2)(14, 12);


	cin.get();
	return 0;
}


c++高能指針