Virtual class
In object-oriented programming, a virtual base class is a nested inner class whose functions and member variables can be overridden and redefined by subclasses of an outer class. Virtual classes are analogous to virtual functions. The run time type of a virtual class depends on the run time type of an object of the outer class. (Just like the run time type of an object decides which virtual function should be used.) A run time instance type of the outer class object not only decides on the polymorphic type of its own type object, but also on a whole family tree of virtual class members.
In object-oriented programming, a virtual base class is a nested inner class whose functions and member variables can be overridden and redefined by subclasses of an outer class. Virtual classes are analogous to virtual functions. The run time type of a virtual class depends on the run time type of an object of the outer class. (Just like the run time type of an object decides which virtual function should be used.) A run time instance type of the outer class object not only decides on the polymorphic type of its own type object, but also on a whole family tree of virtual class members. include class Machine { public: void run() { } class Parts { public: virtual int get_wheels() = 0; virtual std::string get_fuel_type() = 0; }; }; // The inner class "Parts" of the class "Machine" may return the number of wheels the machine has. class Car: Machine { public: void run() { std::cout Any object of class type Machine can be accessed the same way. The programmer can ask for the number of wheels (by calling get_wheels() ), without needing to know what kind of machine it is, how many wheels that machine has, or all the possible types of machines there are. Functions like get_fuel_type() can be added to the virtual class Parts by the derived class Car . ==See also== Inheritance (object-oriented programming) Superclass (computer science) Virtual inheritance Virtual function ==References== ==External links==
References
No reference rows published for this article.
Cite this article
MLA
"Virtual class." encyclopegia.org, 2023, https://encyclopegia.org/wiki/virtual-class. Accessed 24 November 2026.
Chicago
"Virtual class." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/virtual-class.
APA
encyclopegia.org. (2023). Virtual class. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/virtual-class
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON