Hi, all
//Case One
class BasePacket;
int A;
endclass : BasePacket
class My_Packet extends BasePacket;
int C;
endclass : My_Packet
class BaseTest;
BasePacket PB[string];
virtual function void Create_PKT(string s);
PB[s] = new();
endfunction : Create_PKT
virtual function void Configure_PKT(string s);
PB[s].A = 1;
endfunction : Configure_PKT
virtual function void printP(string s);
$display("BaseTest::PB[%s].A is %d", s, PB[s].A);
endfunction : printP
endclass : BaseTest
class My_Test extends BaseTest;
virtual function void Create_PKT(string s);
My_Packet MP = new();
PB[s] = MP;
endfunction : Create_PKT
virtual function void Configure_PKT(string s);
// My_Packet mp;
super.Configure_PKT(s);
My_Packet mp;
$cast(mp, PB[s]);
mp.C = 2;
PB[s] = mp;
endfunction : Configure_PKT
virtual function void printP(string s);
// My_Packet mp;
super.printP(s);
My_Packet mp;
$cast(mp, PB[s]);
$display("My_test::PB[%s].C is %d", s, mp.C);
endfunction : printP
endclass : My_Test
BaseTest T1 = new();
My_Test T2 = new();
initial begin
T1.Create_PKT("StringBase");
T1.Configure_PKT("StringBase");
T1.printP("StringBase");
T2.Create_PKT("MY_String");
T2.Configure_PKT("MY_String");
T2.printP("MY_String");
end
//Output Information (Compiler Report Error)
//
//near "mp": syntax error, unexpected IDENTIFIER, expecting #
//Case Two
class BasePacket;
int A;
endclass : BasePacket
class My_Packet extends BasePacket;
int C;
endclass : My_Packet
class BaseTest;
BasePacket PB[string];
virtual function void Create_PKT(string s);
PB[s] = new();
endfunction : Create_PKT
virtual function void Configure_PKT(string s);
PB[s].A = 1;
endfunction : Configure_PKT
virtual function void printP(string s);
$display("BaseTest::PB[%s].A is %d", s, PB[s].A);
endfunction : printP
endclass : BaseTest
class My_Test extends BaseTest;
virtual function void Create_PKT(string s);
My_Packet MP = new();
PB[s] = MP;
endfunction : Create_PKT
virtual function void Configure_PKT(string s);
My_Packet mp;
super.Configure_PKT(s);
//My_Packet mp;
$cast(mp, PB[s]);
mp.C = 2;
PB[s] = mp;
endfunction : Configure_PKT
virtual function void printP(string s);
My_Packet mp;
super.printP(s);
//My_Packet mp;
$cast(mp, PB[s]);
$display("My_test::PB[%s].C is %d", s, mp.C);
endfunction : printP
endclass : My_Test
BaseTest T1 = new();
My_Test T2 = new();
initial begin
T1.Create_PKT("StringBase");
T1.Configure_PKT("StringBase");
T1.printP("StringBase");
T2.Create_PKT("MY_String");
T2.Configure_PKT("MY_String");
T2.printP("MY_String");
end
//Output Information
//
//# BaseTest::PB[StringBase].A is 1
//# BaseTest::PB[MY_String].A is 1
//# My_test::PB[MY_String].C is 2
I designed two cases as above, ran case one, the simulator reported error as above.
Would like to tell me the different of the declaration class handle before and after the super call?
Thank you in advanced.
BR
QIN