Accessing a class inside pkg

Hi,

Following code is not working for me, it giving error while declaring a variable of type class abc.

class abc
int x;
endclass

package xyz;
class abc2;
abc abc_h; //getting error here
endclass
endpackage

If package is compiled as separate unit, then why following code works even though classes inside tb_pkg using uvm_classes? Please explain.

`include “uvm_macros.svh”
import uvm_pkg::*;

`include “…/tb_pkg.sv”
import tb_pkg::*;

module mod;


endmodule

Thanks,
Rahul

In reply to rahulkumarkhokher@gmail.com:

Please use code tags when posting your code and provide more descriptive error messages.

In reply to dave_59:

Hi,

Following code is not working for me, it giving error while declaring a variable of type class abc.

class abc
int x;
endclass

package xyz;
class abc2;
abc abc_h; //getting error here : data type is not recognized
endclass 
endpackage

If package is compiled as separate unit, then why following code works even though classes inside tb_pkg using uvm_classes? Please explain.

`include "uvm_macros.svh"
import uvm_pkg::*;

`include "../tb_pkg.sv"
import tb_pkg::*;

module mod;
..
..
endmodule

Thanks,
Rahul

Items within packages shall not have hierarchical references to identifiers except those created within the package or made visible by import of another package. A package shall not refer to items defined in the compilation unit scope.

In reply to dave_59:

then why following code works even though classes inside tb_pkg using uvm_classes? Please explain.

`include "uvm_macros.svh"
import uvm_pkg::*;

`include "../tb_pkg.sv"
import tb_pkg::*;

module mod;
..
..
endmodule

Thanks,
Rahul