[Gambas-user] newbie question virtual classes

Christopher Brian Jack brian at ...1334...
Wed Feb 1 08:55:45 CET 2006


On Wed, 1 Feb 2006, Benoit Minisini wrote:

> > class ListBox;
> > class ListBoxItemIMP;
> >
...
...
> >   ...
> > };
> >
> >
> > -- Christopher Brian Jack
> >
>
> 'Virtual' class in Gambas has nothing to do with 'virtual' class in C++. I
> admit I badly chosen the word, but C++ did too, in a different way.

You have to admit though I came pretty close with the C++ snippet to what
is happening (in C++ references prevent creation objects).  The only thing
I forgot to do is privitize the copy constructors and the assignment
operators in the 'internal' classes.

> A virtual class is actually a way for an object of a real class to look like
> another class, said virtual. Maybe 'pseudo-class' would be a better word.

> You cannot instanciate a virtual class. You can only use it temporarily inside
> an expression.
>
> For example: MyTreeView[key] returns a '.TreeViewItem' from its key, but you
> cannot put it inside a variable. You can only use it inside an expression,
> like MyTreeView[key].Text, or inside a WITH...END WITH control structure:

Yes this is where a limitation in Gambas does indeed necessitate the
special non-creatable classes because there are no "reference" types.
In C++ there is [a reference data type] and you could assign the object
back from the ListView's [] operator to a ListViewItem& but all operations
that would create an object would be prevented by the
constructor, destructor, copy-constructor and assignment operator all
being made private members in the 'internal' class.

Again I think the C++ snippet comes very close in approximation to what
the Gambas scenario is doing (that is, presenting an interface that does
not allow temporary object creations).

Brian




More information about the User mailing list