Same class names in different files


I have taken up verification of a subsystem. It has a 3rd party UVC, which has a file name and it has the line below:

class virtual_sequence extends uvm_sequence;

My predecessor had added one more file called file at one hierarchy up and it has the same line below:

class virtual_sequence extends uvm_sequence;

This was compiling and running fine. Now I have changed the as below (as part of clean up and good coding guideline):

class top_virtual_sequence extends uvm_sequence;

This change gives compile error (which is related to the UVC). My question is:
Is it possible to have same class name inside two different files?


In reply to mpattaje:

Yes if they belong to different packages.

In reply to mpattaje:

Of course you can. But you are overwriting the first class definition with the second one when compiling the code, i.e. you could exclude the first class definition from the compile. When you are renaming this sequence you are doing something differently.

In reply to mpattaje:
You can declare two of the same class names as long as they are declared in different scopes. It does not matter if they are in the same file or different files; they need to be in different scopes, otherwise that is a compilation error.
Then you need to be careful of how you reference the class name if you are outside the scope where the class is declared. If the class is declared in a package, you can choose which package to import, or you can explicitly reference the package_name::class_name.