public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* incompleteness
@ 2004-02-08 15:10 Petar Maymounkov
  0 siblings, 0 replies; only message in thread
From: Petar Maymounkov @ 2004-02-08 15:10 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-02-08 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-08 15:10 incompleteness Petar Maymounkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).