微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微电子和IC设计 > IC验证交流 > 请教下$cast这个函数的用法

请教下$cast这个函数的用法

时间:10-02 整理:3721RD 点击:
对$cast的使用还是不太明白,看到这段代码,不知道是什么意思,或者说为什么这样写?这样写有什么好处?
virtual function bit compare(vmm_data actual , vmm_data expected);
abp_rw act,exp;
$cast(act,actual);
abp_rw 是一个extends vmm_data的一个class
求高人指教~

For specified example, act is an object of class apb_rw, extended from vmm_data. SystemVerilog std says that assignment of parent class object (Actual) to child class object (act) should be done through casting. Child class object by the way can be used anywhere, where a parent class object can be used without casting.

类似于C++中的dynamic_cast

$cast is used to pass arguments(or also we call it handle):
$cast(act,actual) means act points to the object referenced by actual
I think there is no big difference with direct passing method "act=actual" if you don't want to check type of object.

谢谢各位,学到不少~非常感谢!

顶两位高手的解答,很清楚,让这个也困扰我很久的问题得到解答!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top