0

I have a function:

bool IntersectBoxBox(IShape3D* a, IShape3D* b)
    {
        Box* boxA = (Box*)a;
        Box* boxB = (Box)b;

        return(boxA->Intersects(boxB));
    }

and it's called when the 2 IShape3D's are determined to be a box and a box type (there is a IShape3D->GetType() method).

Anyways,the problem is that Intersects takes a Box& box,so I can't pass it a pointer. Is there an cheap way to convert the arguments?

4

2 回答 2

10

Just dereference your pointer (*boxB).

于 2013-01-15T00:06:56.473 回答
3

You can't in general – this is only possible when you have a non-nullptr. That may indeed be quite relevant when dynamic casting is involved here, as it seems (don't use C-style casts for dynamic dispatch). After eliminating the nullptr case, you may indeed simply dereference the pointer, *boxB.

于 2013-01-15T00:11:39.507 回答