This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
incompleteness
- From: Petar Maymounkov <petar at scs dot cs dot nyu dot edu>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 8 Feb 2004 10:10:49 -0500 (EST)
- Subject: incompleteness
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