sv中声明和定义

标题1. class constructor ---- new

SV中通过new构造函数来创建对象,在创建对象的过程中,可以做一些初始化工作。new函数没有返回值,他的返回类型就是赋值表达式中左值的类型。如果没有自己定义new函数,那么SV会调用默认的new函数;一个派生类的new函数会先调用父类的new函数。 2. super  The super keyword is used from within a derived class to refer to members, class value parameters, or local value parameters of the base class(super关键字用来引用父类中的成员、参数等). It is necessary to use super to access members, value parameters, or local value parameters of a base class when those are overridden by the derived class(如果父类中的成员、参数被子类重载了,并且还想在子类中使用重载之前的父类的成员,那么要用super)。但是super只能用一层,如果super.super.new()这种方式,不行。  A super.new call shall be the first statement executed in the constructor. This is because the superclass shall be initialized before the current class and, if the user code does not provide an initialization, the compiler shall insert a call to super.new automatically. super.new()会对父类中定义的成员初始化。 3. 声明和例化声明是声明一个变量,其中保存类对象的句柄。例化是通过构造函数,创建对象,分配内存空间,并将声明的句柄指向这段内存空间。虽然在SV中可以在声明的时候例化对象,但是不建议如此。一般是在块语句之外声明类对象,在块语句内例化对象;可以控制对象的实例化顺序。 4. 对象解除在SV中自动管理对象创建时分配的内存。SV会记住指向一段内存的句柄的数目,如果一段内存没有一个句柄指向它,那么它就会被自动释放掉。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值