incompleteness

Petar Maymounkov petar@scs.cs.nyu.edu
Sun Feb 8 15:10:00 GMT 2004


Hello,

This is not really a bug, but I think it is a sort of incompletelness of 
the C++ language. I wanted to hear a second opinoin maybe. So consider the
example:

template<class SUPER>
class sub {
public:
  void use_super () {
    static_cast<SUPER *> (this)->some_func ();
  }
};

class super : public sub<super> {
public:
  void some_func () { ... }
};

This is perfectly valid code, which allows the "sub" class to use 
functionality of the deriving class. The most important thing about this
example is that the transition from sub to super is static (so its fast).

The problem is that the above cannot be accomplished in the more 
complicated scenario, where super is declared like this:

class super : public virtual sub<super> { ...

Because then the static_cast refuses to be used on virtual base classes.
Yet, in a situation when you know the type of the object pointed to by the
pointer, you should have a way of static casting from virtual base to that
fixed type. 

I've been frustrated that this is not possible. Any comments will be well 
appreciated.

Thanks,
Petar



More information about the Gcc-bugs mailing list