【发布时间】:2020-11-27 06:15:50
【问题描述】:
在.hpp 文件中
class trees
{
public:
virtual void func();
private:
void world(uint8_t alpha, uint8_t beta);
}
在 a.cpp 中
#include "a.hpp"
void trees::world(uint8_t alpha, uint8_t beta)
{
}
void trees::func()
{
hello( hi, world ); //error
}
其中hello 和plant 在单独的文件中如下:
int hello(struct b* c, plant d);
typedef void plant(uint8_t alpha, uint8_t beta);
第 2nd 参数给出错误提示 (tress::*) is not compatible with parameter of type world
我知道我需要实例化 obj,但我不知道该怎么做。
【问题讨论】:
-
@churill "hello(hi,world) 在函数内部被调用。我已经编辑了问题。现在有意义吗?
-
hello不是tree的成员,因此它不知道其他tree成员,例如tree::world。此外,(非静态)成员函数不等于非成员函数。成员函数需要调用对象,而非成员函数不需要。这有很大的不同。 -
@Someprogrammerdude 我错了,我刚刚编辑了问题
标签: c++ function-pointers pointer-to-member