swapnilm Posted January 18, 2013 Report Share Posted January 18, 2013 Dear all, can anyone plz tell me, why do we use 'virtual' word in the declaration of every class in UVM library when it is inherited.? Ex: virtual class uvm_test extends uvm_component So why this virtual word is used here? Whats the meaning of this virtual. Any guidance would be appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
whiteriver Posted January 18, 2013 Report Share Posted January 18, 2013 (edited) This is related to polymorphism, google for 'systemverilog polymorphism' and you'll find many good answers for that. An Example is to create a class 'car' which has a virtual method (functions in classes are called methods) 'WhoAmI' that returns "I'm a car". Later you extend this class to create 'toyota' which is a child class to 'car'. This child class has the same method 'WhoAmI' but it returns "I'm a toyota". When using these classes, you can instantiate a 'car' and assign it a 'toyota' (because a toyota is a car) and if you call WhoAmI, it will return "I'm a toyota", even though you have instantiated a 'car'. Edited January 18, 2013 by whiteriver Quote Link to comment Share on other sites More sharing options...
rajneeshT Posted January 18, 2013 Report Share Posted January 18, 2013 Use of Virtual keyword while declaration of a class makes it an abstract class, which means we can only extend this class but we can not create objects of it. Quote Link to comment Share on other sites More sharing options...
swapnilm Posted January 18, 2013 Author Report Share Posted January 18, 2013 Thanks to both of you for your replies. Can you also give some guidance on virtual methods and how are they different from virtual classes..? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
whiteriver Posted January 18, 2013 Report Share Posted January 18, 2013 take rajneeshT's explanation for virtual class, my explanation was about virtual methods inside a class, which is not the same thing. The example on virtual classes is to have a placeholder for the class structure, you can declare variables and methods on the virtual class, but as rajneeshT said, you can't instantiate it directly, so you have to extend it and then instantiate the child classes. Quote Link to comment Share on other sites More sharing options...
swapnilm Posted January 18, 2013 Author Report Share Posted January 18, 2013 Thanks for your reply Quote Link to comment Share on other sites More sharing options...
dave_59 Posted January 18, 2013 Report Share Posted January 18, 2013 swapnilm, It is possible you are looking at the Accellera SV 3.1a LRM which does not explain this topic very well. (It is hard for me to believe it is now 9 years old) It does not mention the relationship between virtual classes and pure virtual methods at all. The IEEE 1800-2005 LRM clarified this, and the 1800-2009 LRM is the most current, with the 1800-2012 LRM just about to be published. Quote Link to comment Share on other sites More sharing options...
swapnilm Posted January 19, 2013 Author Report Share Posted January 19, 2013 yes Sir, I am following SV 3.1a only. Its not mentioned there proeperly. Thanks for your feedback, will look into IEEE 1800-2005 LRM. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.