c++ - “void (Test::*)()”类型的值不能分配给“void (*)()”类型的实体
问题描述
函数指针有问题,我想在函数上创建一个指针,但是当我试图指向必须指向哪个函数指针时,下一个文本出现错误:“void (Test:: )()类型的值" 不能分配给类型为 "void ( )()" 的实体。这是我的代码:
testh.h:
#pragma once
#include<iostream>
using namespace std;
class Test {
public:
Test();
void hello();
void goodBye();
~Test();
private:
void(*b1)();
void(*b2)();
void(*functPtrs[1])();
};
test.cpp:
#include"testh.h"
Test::Test() {
b1 = hello;
b2 = goodBye;
functPtrs[0] = b1;
functPtrs[1]=b2;
}
void Test::hello() {
cout << "hello" << endl;
}
void Test::goodBye() {
cout << "Goodbye" << endl;
}
Test::~Test() {
}
Thanks in advance
解决方案
推荐阅读
- javascript - 在反应中创建动态高度宽度图像组件
- javascript - 将不规则对象转换为 sipmle 对象
- html - 如何在引导卡中使用 fa 图标?
- visual-studio-code - 如何在 VSCode 中进行前进/后退导航但忽略手动光标(例如:上/下)运动?
- flutter - 颤动火基地获取标签栏tb栏视图中的嵌套集合
- c++ - WIA 运行时检查失败 #0 C++(Windows 图像采集)
- javascript - 在 Array 上未检测到 Vue 更改
- python - 子集日期列表
- javascript - Javascript innerWidth 而不是 window.innerWidth
- c# - 方法 'all' 没有重载需要 0 个参数