无法调用成员函数,尝试正确执行此操作仍然失败

Cannot call member function, tried to do it properly still fails

本文关键字:执行 操作 失败 调用 成员 函数      更新时间:2023-10-16

我在头文件中实现了一个新类(ProtoType(。看起来像这样:

class ProtoType : public Test
{
public:
uint32_t test();

};
class RealProtoType : public Real
{
public:
uint32_t real();

};

然后在C++文件中我做了这个

uint32_t ProtoType::test()
{
return 5;
}
uint32_t RealProtoType::real()
{
uint32_t holder = ProtoType::test();
}

然后我在编译时收到此错误

错误:无法调用成员函数"uint32_t ProtoType::test((" 没有对象uint32_t原型::测试((;

但我仍然失败,我该如何解决这个问题?

由于ProtoType::test()是一个非静态成员函数,因此您需要一个类型ProtoType的对象来调用该函数:

uint32_t RealProtoType::real()
{
ProtoType foo;
uint32_t holder = foo.test();
return 42;
}