【SystemVerilog基础】多态和$cast动态类型转换继续深入(虚函数/虚任务理解)(virtual)

速记:

  • 虚函数/虚任务理解:被virtual修饰的类成员函数称为虚函数。虚函数是动态绑定的。在不改变基类的前提下,如果子类需要修改基类的行为(即重写与基类函数同名的函数),就应该在基类中将相应的函数声明为虚函数。虚函数是多态的一种重要实现方式。
  • 父类的指针可以指向子类的对象
    • 父类的指针在指向子类对象时,可以动态索引到子类重写的子类方法。
  • 子类的指针不可以直接指向父类的对象

定义一个基类的句柄,如果是单态的话,句柄的类型就决定了对象的类型。比方说句柄的类型是类A,那么不管这个句柄指向什么类型的对象,它都是调用A里面的方法。
而多态是说一个类的指针,可以根据指向的对象的类型,显示出该对象对应的特性,也就是调用对象所对应的类型里面的方法。比方说句柄的类型是类A,该句柄指向的对象类型是类B,则会调用B里面的方法。

  • 1、多态的实现方式:虚函数(virtual):被virtual修饰的类成员函数称为虚函数
  • 2、基类中某一成员函数声明为virtual虚函数后,派生类中的同名函数(同名、同参、同类型)自动生成虚函数

一、多态

1.1、多态含义

通过父类的指针调用子类的对象方法。

1.2、多态应用场景

在不改变原有代码的基础上,想覆盖原有代码类中的函数;

1.3、多态代码实例

poly.sv

class bird;
  int a = 'h1;
  int b = 'h2;

  function void display();
SystemVerilog 中 $cast 的多态性实践指南 本文深入探讨了SystemVerilog中$cast操作符在多态性编程中的关键应用,包括向下转型、向上转型及枚举类型的特殊处理。通过实际案例演示如何安全实现类型转换,避免常见陷阱,并分享验证环境中的最佳实践,帮助开发者高效利用$cast提升代码灵活性和可维护性。 阅读详情

相关推荐

面向对象编程在SystemVerilog中的核心要点解析

深入剖析SystemVerilog中类、继承、多态与封装等面向对象机制的实际应用,结合验证平台构建场景,说明如何用systemverilog提升UVM测试用例的复用性与可维护性。

weixin_34885746的博客 336

数字IC验证笔试核心大题精解(UVM+SystemVerilog)

本文深入解析数字IC验证笔试中的核心大题,涵盖UVM验证平台构建、SystemVerilog关键技术及典型笔试题目精讲。重点讲解UVM组件、sequence机制、工厂模式与对象覆盖等验证工程师必备技能,帮助读者掌握数字IC验证的核心要点,提升笔试通过率。

weixin_34414196的博客 356

【system verilog】OOP属性下的构造函数new,虚方法virtual和cast方法(终)

前几天有朋友和我讨论,明明$cast函数的功能是修改句柄的指向,为什么我们总是称之为强制类型转换函数?下班的路上我想了一下,感觉还是因为句柄的指向规则和调用特性使得$cast看起来确实是在完成强制类型转换功能。从这一点看,实际上右侧的实例类型并没有被强制转换转换成左侧句柄的类型。但是呢,别忘了还有另外一个性质:父类句柄指向子类空间时,无法调用父类中不存在、子类拓展出来的方法,具体实验请参见系列文章的第四篇。从结果上看,仿佛是右侧的子类空间被强制转换为左侧父类句柄的数据类型了。

moon9999的博客 515

主流算力卡性能对比分析

超大规模AI训练/HPC:优先选择NVIDIA H100或AMD MI300X,需关注显存带宽和多卡互联能力。企业级AI训练:NVIDIA A100性价比更高,生态成熟。国内自主可控需求:华为昇腾910B是首选,支持液冷和低功耗设计。本地AI推理/游戏:NVIDIA RTX 4090或RTX 5090性价比突出,但需注意显存容量限制。边缘计算/低功耗场景:华为昇腾310或清微智能TX536(能效比6.3TOPS/W@INT8)更合适。

m0_69867914的博客 7848

告别单一帧:在CFD-POST中完整加载Fluent瞬态计算结果的实战指南

本文详细介绍了在CFD-POST中完整加载Fluent瞬态计算结果的实战指南,解决工程师常见的只能看到最后一帧数据的问题。通过Fluent端的正确设置和CFD-POST端的完整加载技巧,帮助用户高效处理瞬态数据,提升后处理效率。文章还提供了常见问题排查、性能优化和高级后处理技巧,适用于Workbench环境下的流体流动分析。

weixin_29284657的博客 546

别再为OpenBCI_GUI安装发愁了!保姆级教程带你从Processing配置到成功运行(附常见错误解决)

本文提供了一份详细的OpenBCI_GUI安装教程,涵盖从Processing配置到成功运行的全过程,特别针对常见错误提供了解决方案。通过环境搭建、软件依赖安装、源码处理及首次运行实战,帮助用户高效完成数据可视化工具的部署与使用。

weixin_28366475的博客 275

洛谷P5707 【深基2.例12】上学迟到(c语言)

第一篇题解 题目描述 yyy 的学校要求早上 8 点前到达。学校到 yyy 的家一共有 s(s\le 10000)s(s≤10000) 米,而 yyy 可以以 v(v<10000)v(v<10000) 米每分钟的速度匀速走到学校。此外在上学路上它还要额外花 10 分钟时间进行垃圾分类。请问为了避免迟到 yyy 最晚什么时候出门?输出 HH:MM 的时间格式,不足两位时补零。由于路途遥远, yyy 可能不得不提前一天出发,不过不可能提前超过一天。 输入格式 两个正整数 s,v,意思已经在题目中给定

cc_love_program的博客 1万+

PCB板质量测试和PCB板

PCB板质量测试和板厂

weixin_51370842的博客 522

Spring Authorization Server自定义密码模式:突破标准OAuth2限制,实现MFA与复杂业务集成

OAuth 2.0授权框架是构建现代应用安全体系的基石,其密码模式(Resource Owner Password Credentials Grant)提供了一种直接的资源所有者凭证交换令牌的机制。该模式的核心原理是客户端收集用户密码并直接向授权服务器请求访问令牌,适用于受信任的客户端场景。在技术价值上,它简化了某些传统应用的OAuth集成流程。然而,标准实现往往难以满足复杂的现实业务需求,例如需要集成多因素认证(MFA)、对接外部LDAP目录服务或执行自定义密码加密校验等场景。Spring Authori

weixin_34302561的博客 442

LVGL 蜂巢气泡菜单(Hex Menu)

h。

摸鱼专家 188

把注释掉的代码删除掉:在 SAP ABAP 团队里打造可回溯、可测试、可演进的代码库

摘要 SAP ABAP项目中常见的"注释掉代码"反模式存在严重隐患:它增加代码噪音,制造虚假安全感,并可能引发安全和合规风险。Clean ABAP指南明确建议删除这类代码,理由包括: 版本控制系统已提供完整历史回溯能力 注释代码会误导开发者,增加理解成本 临时禁用需求应通过Feature Toggle实现 必须保留的参考代码应放入$TMP等隔离区域 团队应建立自动化检查机制,将"删除注释代码"纳入工程规范,确保代码库只表达当前有效的行为逻辑。在AI时代,可以利用工具辅

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2457

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

上一篇: 【SystemVerilog基础】SystemVerilog Assertion 概述
下一篇: 【SystemVerilog基础】fork...join_none 引发的一些思考(包含在for循环中使用fork...join_none的坑)
MoorePlus
博客等级 码龄3年 232粉丝 98原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MoorePlus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值