qinhailiang Posted January 22, 2014 Report Share Posted January 22, 2014 Hi, all I has an example as follow: class BasePacket; int A = 1; int C = 2; function void printA; $display("BasePacket::A is %d", A); endfunction : printA virtual function void printC; $display("BasePacket::C is %d", C); endfunction : printCendclass : BasePacketclass My_Packet extends BasePacket; int A = 3; int C = 4; function void printA; $display("My_Packet::A is %d", A); endfunction: printA virtual function void printC; $display("My_Packet::C is %d", C); endfunction : printCendclass : My_PacketBasePacket P1 = new;My_Packet P2 = new; Case one: initial begin//P1 = P2;P1.printA;P1.printC;$cast(P2, P1);P2.printA;P2.printC;end ...# BasePacket::A is 1# BasePacket::C is 2# ** Error: (vsim-3971) $cast to type 'class work.obc_pkg_sv_unit::My_Packet' from 'class work.obc_pkg_sv_unit::BasePacket' failed in file ../../sv/top/bip4_vtop.sv at line 80.# Time: 0 ps Iteration: 0 Instance: /bip4_vtop# My_Packet::A is 3# My_Packet::C is 4... Case Two:initial beginP1 = P2;P1.printA;P1.printC;$cast(P2, P1);P2.printA;P2.printC;end...# BasePacket::A is 1# My_Packet::C is 4# My_Packet::A is 3# My_Packet::C is 4 ... Case one, I didn't assign P1 with P2, the simulator reported error information as above; the type of P1 is not a superclass of the P2 type? Case twon, I assign P1 with P2 at the begbining, the simulator reported normally as above; Why the assignment of P2 with P1 is cast-compatible after assigned P1 with P2? How to do the simulator judge the cast-compatible? So I want to know what the assignment of P1 with P2 does? Thank you in advanced. BR QIN Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.