函数指针使用出错
  • 板块灌水区
  • 楼主idgg007
  • 当前回复17
  • 已保存回复17
  • 发布时间2021/10/31 15:06
  • 上次更新2023/11/4 01:43:42
查看原帖
函数指针使用出错
297831
idgg007楼主2021/10/31 15:06
#include<graphics.h>
#include<string>
#define VOID void
class Button {
	private:
		struct Text {
			std::string text;
			color_t wordColor;
			int wordSize;
			int pos_x;
			int pos_y;
		};
		int state = 0;
		int FPS_state=0;
	public:
		int FPS;
		int speed;
		Text text;
		color_t linesColor;
		color_t filldColor;
		int lenth_x;
		int lenth_y;
		int position_x;
		int position_y;
		VOID DrawButton();
		VOID UpdateButton(int, int, bool);
		VOID (*buttonRun)();
};
VOID Button::DrawButton() {
	setcolor(filldColor);
	setfillcolor(filldColor);
	bar(position_x, position_y, position_x + lenth_x, position_y + lenth_y);
	setcolor(linesColor);
	line(position_x, position_y, position_x + lenth_x, position_y);
	line(position_x, position_y, position_x, position_y + lenth_y);
	line(position_x + lenth_x, position_y, position_x + lenth_x, position_y + lenth_y);
	line(position_x, position_y + lenth_y, position_x + lenth_x, position_y + lenth_y);
	setcolor(text.wordColor);
	setfont(text.wordSize, 0, "宋体");
	setbkmode(TRANSPARENT);
	outtextxy(text.pos_x, text.pos_y, text.text.c_str());
}
VOID Button::UpdateButton(int mousePosition_x, int mousePosition_y, bool isMouse) {
	if (mousePosition_x < position_x + lenth_x &&
	        mousePosition_x > position_x &&
	        mousePosition_y < position_y + lenth_y &&
	        mousePosition_y > position_y && isMouse) {
		(*buttonRun)();
	}
	if (mousePosition_x < position_x + lenth_x &&
	        mousePosition_x > position_x &&
	        mousePosition_y < position_y + lenth_y &&
	        mousePosition_y > position_y) {
		if (FPS_state > 0) {
			FPS_state--;
			return;
		}
		FPS_state = FPS / speed;
		if (state <= lenth_x + lenth_y) {
			int x1, y1, x2, y2;
			if (state < lenth_y) {
				x1 = position_x;
				y1 = position_y + lenth_y - state;
			} else {
				x1 = position_x + state - lenth_y;
				y1 = position_y;
			}
			if (state < lenth_x) {
				x2 = position_x + state;
				y2 = position_y + lenth_y;
			} else {
				x2 = position_x + lenth_x;
				y2 = position_y - state + lenth_x + lenth_y;
			}
			state++;
		setcolor(linesColor);
		line(x1, y1, x2, y2);
		}
		setcolor(text.wordColor);
		setfont(text.wordSize, 0, "宋体");
		setbkmode(TRANSPARENT);
		outtextxy(text.pos_x, text.pos_y, text.text.c_str());
	} else {
		state = 0;
		DrawButton();
	}
}
#include"BadButton.h"
#include<vector>
class LandIn {
	private:
		std::vector<Button> buttons;
		mouse_msg mouse;
		void GetClasses();
		void AddNewClass();
	public:
		void Land();
};
LandIn landIn;
void LandIn::Land() {
	Button add;
	add.speed = 1200;
	add.FPS = 600;
	add.position_x = 50;
	add.position_y = 50;
	add.lenth_x = 500;
	add.lenth_y = 80;
	add.linesColor = RGB(200, 50, 50); //blue_grean_red
	add.filldColor = RGB(90, 50, 150);
	add.text.pos_x = 182;
	add.text.pos_y = 70;
	add.text.wordColor = RGB(20, 20, 20);
	add.text.wordSize = 40;
	add.text.text = "Add new class";
	initgraph(600, 600);
	add.DrawButton();
	add.buttonRun=AddNewClass;
	buttons.push_back(add);
	add.position_y+=130;
	add.text.pos_y+=130;
	add.text.text = "load Existing";
	add.DrawButton();
	buttons.push_back(add);
	while (true) {
		if (mousemsg()) {
			mouse = getmouse();
		}
		buttons[0].UpdateButton(mouse.x, mouse.y, mouse.is_down());
		buttons[1].UpdateButton(mouse.x,mouse.y,mouse.is_down());
		delay_fps(600);
	}
}
void LandIn::GetClasses() {

}

第二个文件报错:

[Error] cannot convert 'LandIn::AddNewClass' from type 'void (LandIn::)()' to type 'void (*)()'
2021/10/31 15:06
加载中...