Re: Can Objects has multiple classes?



Ryan McDougall <NQG24419 nifty com> writes:

> 	I want to set a per instance property that causes that object to look
> up a vtable with slightly different semantics. The semantics of one
> instance should not interfere with another. This requires two different
> classes. The idea is to jump directly to the correct function without
> incurring the cost of constantly (typeA)? fun1() : fun2(); by setting
> the class pointer at initialization.
> I wish to avoid sub-classing the the semantics since the API is exactly
> the same, and it would cause an undue amount useless code. 
> 
> Is this possible with a minimum of hackishness?

Questions like this about using GOBject should be asked on gtk-list,
not gtk-devel-list.

> ps. If you'd like an example, consider a reverse iterator which is
> identical to forward iterator except next/prev functions are
> reversed.

As Murray said, you could just check the type, but if you are worried
about the overhead of type checking, just reserve a boolean in the
object and do:
        
        if (this->forward_iterator)
                move_forward()
        else
                move_backward()

I don't think replacing the class pointer of an instance is
allowed, and if it were, it would certainly be considered a hack.


Søren



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]