Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 27th, 2006, 02:35 PM
Imre
Guest
 
Posts: n/a
Default Detecting virtual inheritance


Hi

I'd like to create a special cast template function that can be used to
cast a base pointer to a derived one, and uses dynamic_cast if virtual
inheritance is involved, and static_cast otherwise. Unfortunately I
don't know how to properly detect VI.
I've seen a trick for detecting VI, that goes something like:

template <class B, class D>
struct IsVirtualBaseAndDerived
{
class Helper1: public D, public virtual B {};
class Helper2: public D {};
public:
enum { value = (sizeof(Helper1) == sizeof(Helper2)) };
};

This works well, but can't be used to detect if there are additional
inheritance levels between B and D, and VI is used somewhere in the
middle. For example:

class A {};
class B: public A {}; // not virtual
class C: public virtual B {}; // virtual

A is not really a VB of C here, but still, if we are to do an A* -> C*
cast, we should use dynamic_cast due to the VI between B and C.

So, my question is: how could I create some
IsVirtualInheritanceInvolved<B, D> template metafunction?

Thanks,

Imre

  #2  
Old March 27th, 2006, 02:45 PM
Gernot Frisch
Guest
 
Posts: n/a
Default Re: Detecting virtual inheritance

[color=blue]
> So, my question is: how could I create some
> IsVirtualInheritanceInvolved<B, D> template metafunction?[/color]

If I'm not totally wrong, you must provide a function like:
std::vector<std::string> InheritanceInformation();

to all of your classes.
Maybe someone's got a brilliant idea. This one propably sux a lot.


 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles