EXAMPLE: class Base;
typedefenum {bin,oct,dec,hex} radix;
task print( radix r, integer n );
$display(" Enum is %s ",r.name());
$display(" Val is %d",n);
endtask endclass
program main;
initial begin Base b = new;
int bin = 123;
b.print( Base::bin, bin ); // Base::bin and bin are different
end endprogram
RESULT:
Enum is bin Val is 123
In addition, to disambiguating class scope identifiers, the :: operator also allows access to static members (class properties and methods) from outside the class,
EXAMPLE: class Base;
typedefenum {bin,oct,dec,hex} radix;
task print( radix r, integer n );
$display(" Enum is %s ",r.name());
$display(" Val is %d",n);
endtask endclass
program main;
initial begin int bin = 123;
Base::print( Base::bin, bin ); // Base::bin and bin are different
end endprogram
RESULT:
Enum is bin Val is 123
Scope resolution operator :: can be used to access to public or protected elements of a superclass from within the derived classes.
EXAMPLE: class Base;
typedefenum {bin,oct,dec,hex} radix;
endclass
class Ext extends Base;
typedefenum {dec,hex,bin,oct} radix;
In SystemVerilog, the class scope resolution operator applies to all static elements of a class: static class properties, static methods, typedefs, enumerations, structures, unions, and nested class declarations. Class scope resolved expressions can be read (in expressions), written (in assignments or subroutines calls), or triggered off (in event expressions). They can also be used as the name of a type or a method call.
The class scope resolution operator enables the following:
Access to static public members (methods and class properties) from outside the class hierarchy.
Access to public or protected class members of a superclass from within the derived classes.
Access to type declarations and enumeration named constants declared inside the class from outside the class hierarchy or from within derived classes.