encyclopegia.org

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

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1165573834 · 0.5 · snapshot enwiki-001165573834

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.