POV-Ray : Newsgroups : povray.programming : Improved intersection routine for CSG-Intersection objects : Re: Improved intersection routine for CSG-Intersection objects Server Time
8 Jul 2024 19:46:49 EDT (-0400)
  Re: Improved intersection routine for CSG-Intersection objects  
From: Wolfgang Wieser
Date: 20 Dec 2003 05:31:52
Message: <3fe42517@news.povray.org>
Thorsten Froehlich wrote:
>> What you did not mention is some sort of tree structure. I'm not
>> sure about the details, but isn't there the need for a tree traversal
>> to decide if the dynamic_cast is valid? (Think of multiple
>> inheritance...)
> 
> No, you just search through a list.  That list is (in general, but
> necessarily for every case - it may be shorter) as long as the total
> number
> number of classes a class inherited from.  This has to do with the common
> vtable structure.  How exactly it is implemented of course all depends on
> your compiler runtime library implementation.  You may want to check if
> source code is provided for it (many vendors do provide source code).
> 
Okay, and do you think that explains how the following code 
works: 

-----------------------------
#include <iostream>

struct A
{
        int a;
        A():a(1){}
        virtual ~A(){}
};

struct B
{
        int b;
        B():b(2){}
        virtual ~B(){}
};

struct C : A,B
{ };

int main()
{
        C c;
        A *a=&c;
        std::cerr << (dynamic_cast<B*>(a))->b << std::endl;
}
-----------------------------

Obviously, you can cast A to B without either one being derived 
from the other one just because they share a common parent. 

I must admit that I did not spend a lot of time on thinking but 
as for now, I cannot imagine any algoritm which can perform the 
above dymanic_cast without doing tree traversal. 

Wolfgang


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.