0% found this document useful (0 votes)
6 views10 pages

Class resolution 1

The document explains the use of the class scope operator (::) for accessing class members, static members, and resolving namespace collisions. It details the syntax for referring to class members and provides examples of using the extern keyword for methods defined outside the class body. Additionally, it covers typedef classes for forward declarations and their syntax.

Uploaded by

Vinay A J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Class resolution 1

The document explains the use of the class scope operator (::) for accessing class members, static members, and resolving namespace collisions. It details the syntax for referring to class members and provides examples of using the extern keyword for methods defined outside the class body. Additionally, it covers typedef classes for forward declarations and their syntax.

Uploaded by

Vinay A J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Class resolution

• The class scope operator :: is used to specify an


identifier defined within the scope of a class.
• Classes and other scopes can have the same identifiers
• The scope resolution operator uniquely identifies a
member of a particular class
• Class Resolution operator allows access to static
members (class properties and methods) from outside
the class, as well as access to public or protected
elements of super classes from within the derived
classes.
scope resolution operator (::) being used in following
cases

1. Referring a variable defined in a package. You can


import the package as a whole or selectively
2. Referring static members/methods of a class without
an actual object of the class
3. Extern class methods. Defining a class method outside
the body of class
4. To avoid namespace collision
5. Accessing automatic members has an illegal scope of
the access
Syntax : <class_name > :: class_members
Normal properties -:
class_name :: id = 5
Static method -
class_name ::name_function(class_name :: id)
Example
class scope;
bit[31:0]a;
bit[31:0] address;
static bit[31:0] data;
function void display();
$display("address=%x,data=%x",address,data);
endfunction
static function void print();
$display("data=%x",data);
endfunction
extern function void mon();
endclass

function void scope :: mon();


$display("a=%x",a);
endfunction
Conti…….
module tb;
scope name;
initial begin
name=new();
name.display();
name.print();
name.data=100;
name.display();
scope :: data=15;
scope :: print();
name.mon();
// scope :: addr =20 ; //illegal without creating memory.
end
endmodule
Example of Referring a variable
defined in a package
package my_types;
typedef enum { IDLE , START, END } state_e;
endpackage

modue test;
import my_types::* ; //importing whole package
import my_types::state_e; //importing specific type
initial begin
state_e my_state;
end
endmodule
Extern keyword
• If the definition of the method written outside the body of the class, then the method is called an
external method.
• external task. The definition of the task written outside the class body is referred to as an external
task
• to do this, need to declare the method (Function/Task) with an externkeyword in the class body
along with
• any qualifiers (local, protected or virtual)
• full argument list
• The extern qualifier indicates that the body of the method (its implementation) is to be found
outside the class declaration
• Before the method name, the class name should be specified with a class resolution operator to
specify to which class the method corresponds to.
• Note -: Number of arguments, arguments name and argument type should match between method
declaration and method definition
• syntax -: extern function void disp();
Use from outside the class -:
Function void scope :: disp()
Typedef classes
• A typedefis used to provide a forward declaration of the
class.
In some cases, the class needs to be instantiated before
the class declaration. In these kinds of situations,
the typedef is used to provide a forward declaration of
the class.
• Syntax -:
typedef class class_name;
Example
typedef child;
class parent;
child c;
endclass
class child;
parent p;
endclass

module tb();
parent pa_ha;
child ch_ha;
initial begin
pa_ha = new();
ch_ha = new();
end
endmodule

You might also like