In c++ access control works on per-class basis not on per-object basis.
#ifndef MYTIME_H
#define MYTIME_H class MyTime
{
private:
int m_hour;
int m_minute;
public:
MyTime(int hour,int minute=);
~MyTime(); MyTime operator+(const MyTime & time) const;
void Show(); //int GetHour() const;
//int GetMinute() const;
}; #endif
#include "MyTime.h"
#include <iostream> MyTime::MyTime(int hour,int minute)
{
m_hour=hour;
m_minute=minute;
}; MyTime::~MyTime()
{}; MyTime MyTime::operator+(const MyTime & time) const
{
//MyTime sum
// =MyTime(
// time.GetHour()+m_hour+(time.GetMinute()+m_minute)/60,
// (time.GetMinute()+m_minute)%60
// );
//return sum;
MyTime sum
=MyTime(
time.m_hour+m_hour+(time.m_minute+m_minute)/,
(time.m_minute+m_minute)%
);
return sum;
}; void MyTime::Show()
{
std::cout<<"Hour = "<<m_hour<<" , Minute = "<<m_minute<<std::endl;
}; //int MyTime::GetHour() const
//{
// return m_hour;
//};
//int MyTime::GetMinute() const
//{
// return m_minute;
//};
per-class basis not on per-object basis.
Access control in c++ is implemented as a static,compile-time feature.I think it is rather obvious that it is not really possible to implement any meaningful per-object access control at compile time.only per-class control can be implemented that way.
some hints of per-object control are present in protected access specification,which is why it even has its own dedicated chapter in the standard(11.5).But still any per-object features described there are rather rudimentary.Again,access control in c++ is meant to work on per-class basis.
Your "it is not really possible to implement any meaningful per-object access control at compile time". Why not? In void X::f(X&x), the compiler is easily capable of distinguishing this->a and x.a. It's not (always) possible for the compiler to know that *this and x are actually the same object if x.f(x) is invoked, but I could very well see a language designer find this OK.
In c++ access control works on per-class basis not on per-object basis.的更多相关文章
- protected: C++ access control works on per-class basis, not on per-object basis
一个很简单的问题: //为什么BASE::foo()中可以直接通过p访问val? 看本记录标题,这个问题困扰了很长一段时间,终于解决class BASE { private: ...
- Oracle Applications Multiple Organizations Access Control for Custom Code
档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...
- 开源网络准入系统(open source Network Access Control system)
开源网络准入系统(open source Network Access Control system) http://blog.csdn.net/achejq/article/details/5108 ...
- [笔记] Access Control Lists (ACL) 学习笔记汇总
一直不太明白Windows的ACL是怎么回事,还是静下心来看一手的MSDN吧. [翻译] Access Control Lists [翻译] How Access Check Works Modify ...
- WebGoat系列实验Access Control Flaws
WebGoat系列实验Access Control Flaws Using an Access Control Matrix 在基于角色的访问控制策略中,每个角色都代表了一个访问权限的集合.一个用户可 ...
- Enhancing network controls in mandatory access control computing environments
A Mandatory Access Control (MAC) aware firewall includes an extended rule set for MAC attributes, su ...
- Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade
XMLHttpRequest cannot load http://10.164.153.37:8050/WebService/WebService.asmx/wsGetStreetData. Res ...
- Windows Azure Virtual Network (10) 使用Azure Access Control List(ACL)设置客户端访问权限
<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的China Azure. 我们在创建完Windows Azure Virtual Machi ...
- SELINUX、Security Access Control Strategy && Method And Technology Research - 安全访问控制策略及其方法技术研究
catalog . 引言 . 访问控制策略 . 访问控制方法.实现技术 . SELINUX 0. 引言 访问控制是网络安全防范和客户端安全防御的主要策略,它的主要任务是保证资源不被非法使用.保证网络/ ...
随机推荐
- 再思linux内核在中断路径内不能睡眠/调度的原因(2010)【转】
转自:http://blog.csdn.net/maray/article/details/5770889 Linux内核中断路径中不能睡眠,为什么? 这里就行了很深入的讨论,值得一看:http:// ...
- PHP常用函数总结(180多个)
PHP常用函数总结 数学函数 1.abs(): 求绝对值 $abs = abs(-4.2); //4.2 数字绝对值数字 2.ceil(): 进一法取整 echo ceil(9.999); // 10 ...
- JS判断客户端是否是iOS或者Android手机移动端
var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > - ...
- 【Java基础】一些问题
1. HashSet是如何保证数据不重复的: 首先,HashSet添加元素的时候,底层是通过HashMap的put方法来实现的,而添加的元素,则是保存在了hashMap的key里,因为HashMap的 ...
- IE6下面的hover不兼容
第一种解决方法: ie6中hover只是对a标签有作用 必须有href=“”,否则都不管用,如果不能写a标签,还想让ie6下有滑过效果,那只能写javascript或者jquery. 例如:ie6是不 ...
- log4j日志相对路径,Tomcat(第三方和Springboot内置)参数catalina.home和catalina.base的设置
关于Log4j日志相对路径的配置请看:log4j 产生的日志位置设置 和 catalina.home.catalina.base . 由于我们在Log4j的配置中引入了系统属性${catalina.b ...
- LCA上的RMQ模板算法
How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- [转]windows消息机制(MFC)
消息分类与消息队列 Windows中,消息使用统一的结构体(MSG)来存放信息,其中message表明消息的具体的类型, 而wParam,lParam是其最灵活的两个变量,为不同的消息类型时,存放数据 ...
- (翻译)一起使用 .NET 和 Docker——DockerCon 2018 更新
原文:https://blogs.msdn.microsoft.com/dotnet/2018/06/13/using-net-and-docker-together-dockercon-2018-u ...
- head first (三):装饰者模式
看到别人写的,都看不进去,算了还是自己手写一遍吧,算是帮助自己理解了.写的比较简单,例子也比较好懂,什么时候使用自己看着办. 1.定义 装饰者模式:动态地将职责附加到对象上.若要扩展功能,装饰者提供比 ...