c++对象禁止访问类方法
高洛峰
高洛峰 2017-04-17 13:36:24
0
3
558

请问各位有没有什么办法禁止实例化的对象调用类内的某个方法呢

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
Peter_Zhu

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. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!