|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



SCOPE RESOLUTION OPERATOR



EXAMPLE:
     class Base;
         typedef enum {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;
          typedef enum {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;
        typedef enum {bin,oct,dec,hex} radix;
    endclass
    
    class Ext extends Base;
        typedef enum {dec,hex,bin,oct} radix;
        
        task print(); 
            $display(" Ext  classs :: enum values %d %d %d %d ",bin,oct,dec,hex);
            $display(" Base classs :: enum values %d %d %d %d ",Base::bin,Base::oct,Base::dec,Base::hex);
        endtask
    
    endclass
    
    program main;
        initial
        begin
            Ext e;
            e = new();
            e.print();
        end
    endprogram
RESULT:

 Ext  classs :: enum values           2           3           0           1
 Base classs :: enum values           0           1           2           3



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.


Index
Introduction
Class
Object
This
Inheritance
Encapsulation
Polymorphism
Abstract Classes
Parameterised Class
Nested Classes
Constant
Static
Casting
Copy
Scope Resolution Operator
Null
External Declaration
Classes And Structures
Typedef Class
Pure
Other Oops Features
Misc

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer