请问各位有没有什么办法禁止实例化的对象调用类内的某个方法呢
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
If you want to prohibit access to a class method, put this method in private and protected
class Test { public: void func1(); private: void func2(); }
Here func1 can be called from the object, func2 can only be called inside the class.
I don’t understand...private methods cannot be called outside the class.
Yes, write the method (function) to private: After the following, this method is a private method and can only be called in methods of this class. However, objects instantiated by this class cannot call this method. .
If you want to prohibit access to a class method, put this method in private and protected
Here func1 can be called from the object, func2 can only be called inside the class.
I don’t understand...private methods cannot be called outside the class.
Yes, write the method (function) to private: After the following, this method is a private method and can only be called in methods of this class. However, objects instantiated by this class cannot call this method. .