Systemverilog (Green Book) Chapter 5-Classes and Objects (2) Members of Classes

 The members of the class are encapsulated. The default member type is public, and the restricted member types are protected and local:

class clock 
    local bit is_summer = 0;
    local int nclock = 6;
    function int get_clock();
        if(!is_summer) return this.nclock;
        else return this.nclock+1;
    endfunction
    function bit set_summer(bit s);
        this.is_summer = s;
    endfunction
endclass


clock ck;
    initial begin
        ck = new();
        $display("now tome is %0d", ck.get_clock());
        ck.set_summer(1);
        $display("noe time is %0d", ck.nclock);
end

 [6, error]

Analysis procedures:

clock ck first declares a handle ck, then creates an object new ()

The ck.get_clock function calls the object's method, but ck belongs to an external handle and cannot access the local variable nclock. But the local variable can be accessed through the function get_clock.

Some characteristics of the members of the class are:

 

Published 14 original articles · won 10 · views 20,000 +

Guess you like

Origin blog.csdn.net/Jay_who/article/details/105549511