← Back to team overview

dolfin team mailing list archive

Re: down_cast

 

2008/4/13, Garth N. Wells <gnw20@xxxxxxxxx>:
> In the down casting functions in GenericTensor, what's the difference
>  between
>
>    T* t = dynamic_cast<T*>(instance());
>
>  and
>
>    T* t = dynamic_cast<T*>(this);
>  ?


// Assume this is configured to use a PETScVector:
GenericVector * v = new Vector();

// This won't work:
PETScVector * pv = dynamic_cast<PETScVector*>(v);

// This will work (and is what down_cast does):
PETScVector * pv = dynamic_cast<PETScVector*>(v->instance());

This was the only intended usage for instance().


>  Is there much overhead associated with a dynamic cast?
>
>  Garth

I have no idea how much overhead there is, but I'm assuming it won't
be placed in inner loops anyway.

--
Martin


Follow ups

References