SV中virtual作用
1、virtual的作用
关于多态的含义不再做说明,直接来看virtual使用的不同点
- 代码1如下,不使用virtual
class father;function display();$display("This is Father!!);endfunction
endclassclass son extends father;function display();$display("This is Son!!");endfunction
endclassmodule tb;father father_inst;son son_inst;intial beginson_inst = new();father_inst = son_inst; //父类句柄指向子类对象father_inst.display();son_inst.display();end
endmodule
仿真打印结果
This is Father!!
This is Son!!
- 代码2如下,使用virtual
class father;virtual function display();$display("This is Father!!);endfunction
endclassclass son extends father;virtual function display();$display("This is Son!!");endfunction
endclassmodule tb;father father_inst;son son_inst;intial beginson_inst = new();father_inst = son_inst;father_inst.display();son_inst.display();end
endmodule
仿真打印结果:
This is Son!!
This is Son!!
从上述两个代码中发现:
1)不使用virtual,父类句柄虽指向子类对象,但调用的仍是父类本身的函数
2)使用virtual,父类句柄指向子类对象,调用的是子类的函数
类似上述总结结论:
1)声明虚方法时,根据对象来决定调用
2)未声明虚方法时,根据句柄来决定调用
2、cast使用
上面已经说到父类/子类的指向赋值相关,再看下cast的用法。
- 向上转换
子类指向父类,在上述代码中已经出现
son_inst = new();
father_inst = son_inst; //父类指向子类
- 向下转换
father_inst = new();
son_inst = father_inst; //子类直接指向父类(编译报错)
$cast(son_inst,father_inst); //直接使用cast向下转换(编译报错)
直接使用cast向下转换编译报错如下:
正确方式
son son1,son2;
father father_inst;
son1 = new();
father_inst = son1;
$cast(son2,father_inst);
SV中virtual作用相关推荐
- sv中virtual的使用(function/task部分)
virtual function/task的使用: class a;virtual function void a1(); $display("123"); endfunction ...
- UVM中Virtual sequence的作用
virtual sequence是用来实现sequence之间的同步.从字面上理解,即虚拟的sequence.虚拟的意思就是它根本就不发送transaction,它只是控制其他的sequence,起统 ...
- 先导知识:SV中需要了解的基础的面向对象编程的概念
数字芯片验证主要使用的验证语言SystemVerilog,验证方法学是UVM.SV集成了面向对象编程的特点,具有封装.继承.多态等功能.面向对象编程(OOP)是一个大课题,本节仅记录帮助自己了解SV中 ...
- 【仿真设计】仿真技术在智能制造中的作用;智能制造难点在模型,焦点在仿真;汽车行业CAE研究
仿真的概念 仿真从字面意思来理解,也就是模仿真实的环境.通常在仿真领域分为大概六种: 传统的CAE仿真:比如对机构受力的3D模拟,找出机构设计的可能存在的缺陷及极限 系统仿真:俗称物流仿真,是对生产等 ...
- IC基础知识(六)SV中default input #1 output #1的解释
目录 1. clocking-endclocking块 2. clocking shew的含义 3. 实例代码 4. clocking event 5. clock cycle延时 '##' 6. d ...
- sv中静态属性和静态方法
静态属性 类的内存空间是动态分配和释放的,同一个类的不同实例,即使其中变量的名称相同,也是不同的东西. 如果需要一个变量,这个变量能够被一个类的所有实例共享,那么就需要声明这个变量为static. 可 ...
- 人工智能和深度学习发展趋势_AI在学习和发展中的作用
人工智能和深度学习发展趋势 In this series of blogs, AI in HR, we already understood what is AI, what is HR and be ...
- PNAS | 理解单个神经元在深度神经网络中的作用
本次报道论文为发表于PNAS的Understanding the role of individual units in a deep neural network.众所周知,深度神经网络擅长查找可解 ...
- 单个神经元在深度网络中的作用
目录 背景描述 任务一:场景分类任务的分析 数据集与模型 网络分析方法 实验结果 实验结果分析 实验结果验证 任务二:场景生成任务的分析 背景描述 大量的实验证明,深度神经网络擅于找到大型数据集上的分 ...
最新文章
- Notes客户端重新配置批处理
- 转:Eclipse自动补全功能轻松设置
- 2020-10-14 B树 概念添加删除笔记
- 浅谈Git的基本工作流程与简单的Git命令
- mysql workbench导入sql_MySQL Workbench 导入sql脚本-Go语言中文社区
- element UI 制作模糊搜索框
- 前端换行显示,后端返回br
- BZOJ2683 简单题(CDQ分治)
- 快能通小学生计算机的游戏,亲子小游戏,帮助孩子更快学会交通安全知识
- 自定义分页 html,MVC 自定义HtmlHelper帮助类型之分页
- vue“路由懒加载” 技术,让网页快速加载 (优化篇)
- C#LeetCode刷题之#206-反转链表(Reverse Linked List)
- Lesson Plan 教学计划 翻译
- 六西格玛绿带考试模拟试卷--多选题|优思学院
- 边境的悍匪—机器学习实战:第十九 大规模训练和部署TensorFlow模型
- 短视频直播电商抖音项目孵化流程运营带货商业计划书方案范本
- Vue全家桶学习笔记:Vue Router篇
- 你真的了解Linux(Deepin)的软件商店吗?(内附极力推荐的软件)
- 想要转行成为程序员该怎么做呢?
- 省钱兄游戏陪玩小程序APP源码uniapp前端源码适配支持(APP+小程序+H5)