c++或systemVerilog这写面向对象编程的class中可以定义指向当前class的指针,但是不能定义当前class的成员变量
1 class Screen{
2 //Screen sc; //error, 'sc' uses undefined class 'Screen'
3 //etc...
4 Screen *sc1; //ok
5 Screen &sc2; //ok
6
7 //etc...
8 };
上述c++的class定义中 line2如果uncomment就会报错,因为此时class Screen还没有定义完成,编译器并不知道如何分配空间。
但是line4和line5却是可以的。
对于line4是定义了一个指向class Screen类型的指针,一个指针为4byte,编译器留出这4byte空间即可。
对于line5和line4的含义相同。
所以对于指针变量来说,在没有给指针变量赋值有效的地址之前,这个指针指向的是一个无效空间或者为null,这时指针就没有什么意义。
下面这段代码为systemVerilog的对应定义方式
1 class uvm_base_case_0 #(type REQ) extends uvm_test;
2 typedef uvm_base_case_0 #(REQ) this_type;
3 protected int aaa;
4 local int bbb;
5 this_type case_xxx;
6 this_type case_q[string];
7 function xxxx
8 xxxxxx
9 xxxxxx
10 endclass
和C++不同的是systemVerilog中line5,6定义的就是一个指针。