开发者_Go百科#include <stdio.h>
class MyClass {
void Foo(const int par); };
void MyClass::Foo(const int par) { }
main() { MyClass A; A.Foo(1); }
Anyone can help me? What is wrong with my code? This is the error I get when compiling with gcc:
error: ‘void MyClass::Foo(int)’ is private
Class members and class member functions are by default private, meaning they can only be accesed by methods of the same class and friends.
class MyClass {
// members declared here will be private
public:
// members declared here will be public
void Foo(const int par);
private:
// private
};
Methods are private
by default. Use
public: void Foo(const int par);
精彩评论