简单介绍一下 protect,public,private 的区别,更详细的随后不上。 欢迎纠错~
以C++为例:
public: 数据成员和函数成员可在成员函数,友元,继承类中直接使用。亦可以作为接口,供类的用户使用(即 A a,
a.change())。
private: 数据成员和函数成员,只能在 类成员和友元 中访问。不能被继承类访问(无论何种继承),虽然作为继承
类的私有成员,但 在 使用过程中,是通过调用基类的构造函数 完成参数的传递的。继承类不能访问基类的私有成员。
protect: 在基类中用法同private,基类对象不能访问。在派生类中,用法同基类的public, 其成员 可被子类访问使用,但不可被 继承类对象直接调用。
#include <iostream>
using namespace std;
class Base
{
private:
int age;
protected:
int num;
public:
virtual void show()
{
num = 1;
cout<<num<<endl;
}
};
class Devi : public Base
{
public:
void show()
{
num = 2;
cout<<num<<endl;
}
};
int main()
{
Base b;
Devi d;
b.show();
d.show(); //ok protected num可被子类使用
//b.num=3; //error
//d.num = 3; //error protected num 不可被子类 对象使用
return 0;
}
继承类的用户 在使用从基类继承的成员时,不仅取决于基类在定义时的访问标号(私有,公有等),还取决
于自身对基类的继承方式。同时,继承类 只能让访问权限越小。
同时,注意区分类的接口继承与实现继承的区别。
接口继承,即类的用户可以直接通过“.”或“->”对函数成员进行调用。
实现继承,即在类的成员函数定义过程中,对数据成员访问权限的继承。
注意区分 类成员与类用户的区别。
类成员包括 数据成员和函数成员,讲的是类的实现。
类用户指 类的对象,讲的是对接口的使用。 通过,对象通过 ".",指向对象的指针通过“->”。
Class A
{
public:
A(string& Name = "lihao",int Age = 21)
{}
virtual void print()const;
private :
string name;
int age;
}
void A::print()const
{
cout<<name<<endl
<<age<<endl;
}
Class B:public A
{
public:
B(string& Name,int Age,int Grade):A(Name,Age),grade(Grade)
{}
private:
int grade;
}
void B::print()const
{
A::print();
cout<<grade<<endl;
}
分享到:
相关推荐
一,public,private,protected的区别public:权限是最大的,可以内部调用,实例调用等。protected: 受保护类型,用于本类和继承类调用。private: 私有类型,只有在本类中使用。二,实例复制代码 代码如下:<?...
C++是C语言的继承,它既可以进行C语言的过程化程序设计,又可以进行以抽象数据类型为特点的基于对象的程序设计,还可以进行以继承和多态为特点的面向对象的程序设计。C++擅长面向对象程序设计的同时,还可以进行基于...
三种访问权限 public:可以被任意实体访问 protected:只允许子类及本类的成员函数访问 ...public & private继承 = > private protected & public继承 => protected protected & protected继承 => protected protecte
o Public demo version o Small help updates * 3.2.0 beta 3 (20/04/2010) o New: + DLL support (special compatibility with Photoshop plugins) + License Manager is ready + New option [Use clock ...
详细介绍c++类的继承方式,public、private、protect。
* Func: * public strip 过滤属性 * public setAllow 设置允许的属性 * public setException 设置特例 * public setIgnore 设置忽略的标记 * private findElements 搜寻需要处理的...* private protect 特殊字符转义
* * Func: * public strip 过滤属性 * private findElements 搜寻需要处理的元素 * private findAttributes 搜寻属性 * private removeAttributes 移除属性 * private isException...* private protect 特殊字符转义 */
这是Java示例项目,涵盖了大部分Java核心知识,并演示了诸如原始数据类型,注释,类,导入,Scanner,final,Strings,static,private,protected,public,构造函数,数学,hasNextLine,nextLine,getters等概念...
java混淆器,能够对jar、private、public、protect等混淆,防止java的class文件被盗用
Both public/private-key and symmetric key cryptography are supported. It also includes functionality for : digital certificate management using certificate stores, creating and sigining certificates...
Consequently, both private and public sectors depend upon information systems to perform essential and mission-critical functions. In this environment of increasingly open and interconnected systems ...
实心的代表方法 空心的代表属性 绿色的圆表示公有public 黄色的菱形表示保护protect 红色的方形表示私有private 蓝色的三角表示default
我们都很清楚一个简单的单例模式该怎样去实现:构造函数声明为private或protect防止被外部函数实例化,内部保存一个private static的类指针保存唯一的实例,实例的动作由一个public的类方法代劳,该方法也返回单例类...
也是通过查阅网上资料,初略的整理了一下,(包含了final、static、abstract和访问修饰符public、protect、default、private)写成规范文档希望对有需要的提供些帮助
Asymmetric key algorithms (often called public key algorithms) use a pair of keys (i.e., a key pair): a public key and a private key that are mathematically related to each other. In the case of ...
分享给大家供大家参考。具体方法如下: ... <?.../** string filter class * Date: 2013-01-09 * Author: fdipzone ...* public replace 替换非法字符 ...* private protect_white_list 保护白名单 * private resume
Both public/private-key and symmetric key cryptography are supported. Easy XML The Easy XML toolkit provides you with all the necessary XML utilities. With Easy XML you get a CodeGear and W3C DOM ...
Your application is protected by two keys, one key is inside application it‘s a public key and the second it‘s a private key (that only the owner) which are used in combination to encrypt and ...
Employ private and public key cryptography on Windows Mobile devices Enforce fine-grained security policies using the BlackBerry Enterprise Server Plug holes in Java Mobile Edition, SymbianOS, and ...
Federal agencies, industry, and the public now rely on cryptography to protect information and communications used in critical infrastructures, electronic commerce, and other application areas....