【转载】#335 - Accessing a Derived Class Using a Base Class Variable
You can use a variable whose type is a base class to reference instances of a derived class.
However, using the variable whose type is the base class, you can use it to access only members of the base class and not members of the derived class.
In the example below, we have two instances of the Terrier class, which derives from Dog. One instance is referenced by a variable of type Terrier. Using this variable, you have access to all members of the Terrier class. On the other hand, the variable whose type is Dog can only reference members of the Dog class, even though the reference points to an instance of a Terrier.
Terrier bubba = new Terrier("Bubba", , "Happy");
bubba.Growl(); // Can call Terrier.Growl
Dog jack = new Terrier("Jack", , "Surly");
jack.Growl(); // ERROR: Can't call Growl method
原文地址:#335 - Accessing a Derived Class Using a Base Class Variable
【转载】#335 - Accessing a Derived Class Using a Base Class Variable的更多相关文章
- (转载)1248 - Every derived table must have its own alias
(转载)http://hi.baidu.com/lylegend13/item/a79f17eb51f5dff7e0a5d43b 1. select count(distinct CName) fro ...
- 如何实现 Copying derived entities using only base class pointer
#include <iostream> struct CloneableBase { ; }; template<class Derived> struct Cloneable ...
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- 【转载】#330 - Derived Classes Do Not Inherit Constructors
A derived class inherits all of the members of a base class except for its constructors. You must de ...
- [转载] google mock cookbook
原文: https://code.google.com/p/googlemock/wiki/CookBook Creating Mock Classes Mocking Private or Prot ...
- C++ 强制类型转换(转载)
转载自:http://www.weixueyuan.net/view/6329.html 在C++语言中新增了四个关键字static_cast.const_cast.reinterpret_cast和 ...
- 【转载】C++中的基类与派生类
转自:http://www.cnblogs.com/sujz/articles/2044365.html 派生类的继承方式总结: 继承方式 说明 public 基类的public和protected的 ...
- [C++] OOP - Base and Derived Classes
There is a base class at the root of the hierarchy, from which the other class inherit, directly or ...
- 【转载】#344 - Hidden Base Class Member Is Invoked Based on Declared Type of Object
When you use the new modifier to hide a base class method, it will still be called by objects whose ...
随机推荐
- Swagger的坑
swagger.pathPatterns如果是譬如/w/.*,那么如果API中以w开头的描述就会在swagger-ui中显示不出来
- classloader 学习
classloader就是把类文件加载到jvm中供虚拟机使用,先看一个magic小例子: 首先,我定义一个alex/vicky包,然后在这个包内定义一个接口: public interfaceISer ...
- mysql隔离级别与锁,接口并发响应速度的关系(1)
默认隔离级别:可重复读 原始数据 | id | name | addr | | nick | NULL | 事务1 事务2 start transaction start transaction ; ...
- 【ACM】阶乘因式分解(二)
阶乘因式分解(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 给定两个数n,m,其中m是一个素数. 将n(0<=n<=2^31)的阶乘分解质因数,求 ...
- formatter easyui 重命名
function for_method(){ datagridmethod = $('#formethod_datagrid').datagrid({ url : 'loc ...
- Murano Weekly Meeting 2015.08.18
Meeting time: 2015.August.18th 1:00~2:00 Chairperson: Nikolay Starodubtsev, from Mirantis Meeting s ...
- Ubuntu14.04-PXE搭建
什么是PXE? PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从 ...
- PHP函数的引用传递(地址传递)
PHP中的引用: 在PHP中,变量名和变量内容是不一样的,因此同样的内容可以有不同的名字.在PHP中引用意味着用不同的名字访问同一个变量的内容. 比如:$a = 'hello world'; $b = ...
- 小程序 页面到详情的id传递
比如电影列表页跳转到电影详情页 在movie.js获取movieId; processDoubanData: function (moviesDouban, settedKey, categoryTi ...
- 关于docker remote api未授权访问漏洞的学习与研究
漏洞介绍: 该未授权访问漏洞是因为docker remote api可以执行docker命令,从官方文档可以看出,该接口是目的是取代docker 命令界面,通过url操作docker. docker ...