原题
class Thing;
int data;
endclass
module test();
Thing t1,t2,t3;
initial begin
t1 = new();
t1.data=3;
t2=new();
t2.data=4;
t3 = new t2;
t2=t1;
t2.data=8;
$display("t1.data:%0d
",t1.data); //8,t2新赋的值给到t1,说明t2句柄指到了t1的存储空间
$display("t2.data:%0d
",t2.data); //8
$display("t3.data:%0d
",t3.data); //4,t2新赋的值没有给到t3,说明通过new复制的对象本身是有int data的存储空间的
t2 = t3;
t3.data=8;
$display("t3.data:%0d
",t3.data); //8
end
endmodule
解释
句柄就像指针