C++。无法调用成员函数。错误 : "foo is private"
C++. member function cannot be called. error : "foo is private"
#include <stdio.h>
class MyClass {
void Foo(const int par); };
void MyClass::Foo(const int par) { }
main() { MyClass A; A.Foo(1); }
有人能帮我吗?我的代码有什么问题?这是我用gcc编译时得到的错误:
error: ‘void MyClass::Foo(int)’ is private
类成员和类成员函数在默认情况下是私有的,这意味着它们只能被相同类和友元的方法访问。
class MyClass {
// members declared here will be private
public:
// members declared here will be public
void Foo(const int par);
private:
// private
};
方法默认为private
。使用
public: void Foo(const int par);
相关文章:
- Why is UINT32_MAX + 1 = 0?
- C++错误:"error: int aaa::bbb is protected within this context"
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 创建具有 new in 函数和"this is nullptr"异常的对象
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- Is !NaN not a NaN?
- 仅让特定类'Fabric'构造类'Foo'及其所有子类的实例
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- Where is std::hardware_destructive_interference_size?
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- What is unordered_set in C++
- 反转C++ foo(MyClass &) vs foo(const MyClass &)
- 你如何理解"std: :forward is just syntactic sugar"?这是真的吗?
- CMake 错误 - 目标 foo INTERFACE_SOURCES属性包含在源目录中以前缀为前缀的路径
- Is int & foo();一个左值?
- Is there any reason for using if(1 || !Foo())?
- What is an `int foo::*bar::*`?
- C++。无法调用成员函数。错误 : "foo is private"