【转载】#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 ...
随机推荐
- redis 集合
> SADD myset1 a b c (integer) > SADD web maiziedu.com (integer) > SADD web maiziedu.com (in ...
- zabbix监控nginx mysql 服务添加
[root@test2 ~]# rpm -ivh nginx-1.8.0-1.el7.ngx.x86_64.rpm [root@test2 ~]# cd /etc/nginx/ [root@test2 ...
- 在U盘打造个性化PE工具箱+KALI(Persistence)+存储的工作站
基本工具: kali-linux-2018.2-amd64 原版镜像:https://www.kali.org/downloadsWin32DiskImager yunfile 下载较慢,建议自行百度 ...
- C:foreEach
c:forEach用法 <c:foreach>用法 <c:foreach>类似于for和foreach循环 以下是我目前见过的用法:1.循环遍历,输出所有的元素.& ...
- spring boot CrossOrigin不生效?
直接postman, curl, 浏览器访问后端接口, response header是不会自动加上Access-Control-Allow-Origin的. 需要在ajax中调用,客户端reques ...
- python练习六十八:字符串练习
题目:一个商城在搞抽奖的活动,需要在搞活动的宣传单上印刷优惠卷的验证码,验证码规定20位,生成100个 先来个简单的,20位码中只取数字 import random def num_1(num): l ...
- 逐行创建、读取并写入txt(matlab) && 生成文件夹里文件名的.bat文件
fidin=fopen('C:\Users\byte\Desktop\新建文件夹 (4)\tr4.txt','r'); fidout=fopen('C:\Users\byte\Desktop\新建文件 ...
- Django-5.1 模型层 单表操作
7.1 ORM简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开 ...
- 分布式思想和rpc解决方案介绍
1.RPC的诞生 RPC(Remote Procedure Call)远程过程调用,通过这个rpc协议,调用远程计算机上的服务,就像调用本地的服务一样. 不同的服务部署在不同的机器上面,并且在启动后在 ...
- python-综合练习题(if条件语句,while循环,奇数偶数
练习题: 1.使用while循环输入1 2 3 4 5 6 8 9 10 2.求1-100的所有数的和 3.输出1-100内所有的奇数 4.输出1-100内所有的偶数 5.求1-2+3-4+ ...