JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

C++访问控制public private

发布时间 2023-04-16 13:44:06作者: Z_Chan
#include <iostream>
class A{
    public:
        std::string head;
    private:
        std::string body;
};

int main()
{
   A a;
   a.head="888";
   a.body="999";
   return 0;
}

报错结果

main.cpp: In function ‘int main()’:
main.cpp:13:6: error: ‘std::string A::body’ is private within this context
   13 |    a.body="999";
      |      ^~~~
main.cpp:6:15: note: declared private here
    6 |   std::string body;
      |               ^~~~

 

    本栏目推荐文章
  • 连接MySQL时报错:Public Key Retrieval is not allowed的解决方法
  • Qt小知识3.Q_DECLARE_PRIVATE和Q_DECLARE_PUBLIC
  • keno linux error"org.kde.plasma.private.notes" is not installed
  • private关键字
  • 严重:无法访问私钥文件“ /etc/ssl/private/ssl-cert-snakeoil.key”:权限被拒绝
  • System.Private.CoreLib.dll有什么特别的?
  • 18.In the academic world, there is a popular phrase "publish or perish." Academics, therefore, always work hard to keep themselves academically alive through publications.
  • KEILC51编译问题ERROR L104: MULTIPLE PUBLIC DEFINITIONS重复定义
  • 方法用到private ,需要用的get和set方法
  • 深入理解泛型(经典详解):<T> T 和 T的使用以及public <E> List<E> get()泛型方法详解、类型擦除、通配符的使用、泛型类的应用、泛型之间的继承
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们