main.cpp

来自「很好的 关于C++的例子 我想你要是可以把上面的例子都做好了 看明白了 关于函数」· C++ 代码 · 共 57 行

CPP
57
字号
typedef struct Point_STRUCT
{
	int x;
	int y;
}Point;


class Shape
{
public:
	void moveTo(Point newLocation){};
	bool validate() const;
	virtual bool draw() const=0;

};

class Circle:public Shape
{
	bool draw() const;

};

void (Shape::*mf1)(Point)=&Shape::moveTo;




class B
{
public:
	void bset(int val){bval_=val;}
private:
	int bval_;//有的地方私有变量下划线加在前面
};

class D:public B
{
public:
	void dset(int val){dval_=val;}
private:
	int dval_;
};

B b;
D d;
//void (B::*f1)(int)=&D::dsetp;		//错误 
//(b.*f1)(12);						//错误

void (D::*f2)(int)=&B::bset;		//正确
					



void main()
{
	(d.*f2)(11);					//正确
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?