2019-04-16
阅读量:
531
python的折构函数
Perl子例程中的构造函数返回一个对象,该对象是类的一个实例。在Perl中,约定是将构造函数命名为“new”。与许多其他OOP不同,Perl不提供构造对象的任何特殊语法。它使用与该特定类明确关联的数据结构(散列,数组,标量)。
构造函数在哈希引用和类名(包的名称)上使用“bless”函数。
让我们设计一些代码以获得更好的解释:
注意:由于使用了包,以下代码将无法在在线IDE上运行。下面的代码是Perl类或模块文件。将以下文件另存为(* .pm)扩展名。
# Declaring the Package
package Area;
# Declaring the Constructor method
sub new
{
return bless {}, shift; # blessing on the hashed
# reference (which is empty).
}
1;






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论