virtual

A virtual class is a Class which represents a sub-component of a Class, but which you cannot instanciate nor reference into a Variable.

Components written in C/C++

In native components, virtual classes are a mechanism designed so that the user manipulates temporary objects, without being having to create them. It is SO much faster!

Note that the name of a virtual Class must begin with a dot. For example, the name of the virtual class used by the ListView.Item is .listviewitem.

Example

The Property of the qt component ListView uses a virtual class for representing a ListView item.

Virtual classes are just used as datatypes by the interpreter. But the Object used behind is the real Object coming from the real non-virtual Class.

For example, the Item property of the ListView stores the index of the item you want to deal with in the ListView, and returns this ListView. The ListView becomes then a virtual class Object that you cannot store in a Variable. As you must use the virtual class Object immediately, by calling a Method or a property on it, the stored index will be used immediately too.

Components written in Gambas

In components written in Gambas, virtual classes are classes whose name begins with an underscore.

They are actually true classes that work exactly like normal classes, and so they are not faster in any way.