访问说明符,无法调用派生 class 中定义的函数
Access specifier, not able to call a function which is defined in the derived class
我试图了解 C++ 中的访问说明符,所以我从基 class 访问 public 和受保护成员,并在派生 class 中执行添加函数如下所示,
#include<iostream>
using namespace std;
class Base
{
public:
int a;
protected:
int b;
};
class Derived : public Base
{
public:
int sum;
void add()
{
a = 10;
b = 20;
sum = a + b;
}
};
int main()
{
Derived Obj;
Obj.add;
cout << "The sum : " << Obj.sum << "\n";
return 0;
}
但是在编译时我收到以下错误消息"statement cannot resolve address of the overload function"谁能解释一下错误是什么?
提前致谢
函数调用在以下行中缺少括号:
Obj.add;
应该是:Obj.add();
我试图了解 C++ 中的访问说明符,所以我从基 class 访问 public 和受保护成员,并在派生 class 中执行添加函数如下所示,
#include<iostream>
using namespace std;
class Base
{
public:
int a;
protected:
int b;
};
class Derived : public Base
{
public:
int sum;
void add()
{
a = 10;
b = 20;
sum = a + b;
}
};
int main()
{
Derived Obj;
Obj.add;
cout << "The sum : " << Obj.sum << "\n";
return 0;
}
但是在编译时我收到以下错误消息"statement cannot resolve address of the overload function"谁能解释一下错误是什么?
提前致谢
函数调用在以下行中缺少括号:
Obj.add;
应该是:Obj.add();