【C++】cannot access private member declared in class 'Box'
私有的成员和受保护的成员不能使用直接成员访问运算符 (.) 来直接访问。
1、问题代码
#include <iostream>
using namespace std;class Box
{
private:double length; //长度double width; //宽度double height; //高度
};int main()
{Box box1;Box box2;double volume = 0;//box1box1.length = 5;box1.width = 6;box1.height = 7;//box2box2.length = 10;box2.width = 11;box2.height = 12;volume = box1.height*box1.length*box1.width;cout<<volume<<endl;volume = box2.height*box2.length*box2.width;cout<<volume<<endl;system("pause");return 0;
}
2、修改后的代码
#include <iostream>
using namespace std;class Box
{
public:double length; //长度double width; //宽度double height; //高度
};int main()
{Box box1;Box box2;double volume = 0;//box1box1.length = 5;box1.width = 6;box1.height = 7;//box2box2.length = 10;box2.width = 11;box2.height = 12;volume = box1.height*box1.length*box1.width;cout<<volume<<endl;volume = box2.height*box2.length*box2.width;cout<<volume<<endl;system("pause");return 0;
}
结果:
【C++】cannot access private member declared in class 'Box'相关推荐
- 【kafka】InconsistentGroupProtocolException: The group member‘s supported protocols
1.场景1 1.1 概述 org.apache.kafka.common.errors.InconsistentGroupProtocolException: The group member's s ...
- 【iOS】Ambiguous reference to member 'tableView(_:numberOfRowsInSection:)'
报错:Ambiguous reference to member 'tableView(_:numberOfRowsInSection:)' 原因:没有在当前类里面绑定tableview(我这次遇到的 ...
- 【webGoat】Broken Access Control
目录 Broken Access Control 一.Insecure Direct Object References(不安全的直接对象引用) 第2题: 第3题: 第4题: 第5题: 二.Missi ...
- 【181219】VC+Access学生试题考试系统源代码
源码下载简介 VC试题考试系统,使用ACCESS数据库.有很好的参考价值. 系统以考试流程为基础,从专业角度出发,提供科学有效的考试模式.考试时采用系统自动从数据表中选题的方式,评卷时通过核对考生答案 ...
- 【GitHub】Personal Access Token过期导致本地仓库无法直接push到远程
自从GitHub引入access token后,clone 私人仓库到本地需要使用它否则无法push,但access token过期后,原来token clone到本地的仓库,每次push都需要输新t ...
- ASP+Access网站开发相关 【2】ASP + Access登录 列表 分页 查询
包含两个文件:管理员登陆页面adminsearch.asp conn.asp和登录成功之后需要跳转到的查询页面search.asp 1.文件名:adminsearch.asp <%@LANGU ...
- 【Spring】Spring Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect‘ not set
1.配置 server.port=8998 spring.servlet.multipart.max-file-size=2048MB spring.servlet.multipart.max-req ...
- 【BurpSuite】插件开发学习之J2EEScan(下)-主动扫描(61-76)
[BurpSuite]插件开发学习之J2EEScan(下)-主动扫描(61-70) 前言 插件开发学习第11套.前置文章: [BurpSuite]插件开发学习之Log4shell [BurpSuite ...
- 【jQuery】网页文本格式编辑器xheditor
网页文本格式编辑器xheditor是一款优秀的.开源.兼容IE6的JQuery插件.现在很多网站都涉及到用户的交互,很难想象一个没有输入框的网站是怎么样的,你总不能一个给一个空白的文本框给别人吧?如果 ...
最新文章
- java 千分位格式话_Java 字符串小数转成千分位格式
- 聊聊Spring Boot中的优雅停机
- python元组的方法_Python元组及其方法
- VMware 扩展磁盘容量
- 服务器无线不能登录界面,Web认证无法跳转到登录页面
- Web开发中的矢量绘图(vml,svg)处理和应用
- 基于OAuth2的认证(译)
- c语言倒置存放,c语言倒置
- 【会议】2009-11-13
- Mybatis_别名的使用
- eclipse运行java项目
- Firefox必备的24款web开发插件
- php画爱心,在WEB里绘制爱心
- 瑞士军刀1- 剪贴板堆工具-CLCL介绍
- iPad最值得期待的切实改进构想
- 「 科研经验 」思考“工程解决方案”的思维
- 2023年最新阿里云国际版支付方式以及注册教程和方法
- vue能做什么以及特点
- ubuntu如何关联qq邮箱(亲测可用)
- 腾达f3虚拟服务器设置,高手指南win7系统腾达F3路由器设置WIFI定时开关的法子
热门文章
- @value 静态变量_你理解 PHP 中的静态方法吗?
- 微信小程序自定义select下拉选项框
- java impala_impala 概述
- android 数据存储怎么保存图片_文章要保存为TXT文件,其中的图片要怎么办?Python帮你解决...
- Python 一种接触就容易爱上的语言一
- 精选30道Java笔试题解答
- HTML 30分钟入门教程
- Spring 系列,第 3 部分: 进入 Spring MVC
- 局部加权回归、逻辑斯蒂回归、感知器算法—斯坦福ML公开课笔记3
- Hadoop For Windows