Re: [[gnomemm] how to get or check the type of a object???]



"gao chaowei" <chaoweigao hotmail com> wrote:
> thanks for ERDI's answer. but i still do not understand.
> Can you give me an examples. I must know the type before dynamic_cast, 
> right? How can not know the type of the CanvasItem (CanvasPolygon, 
> CanvasLine,CanvasEllipse ...)?
> Suppose the get a varible "item" declared as CanvasItem. how can i get or 
> check its type.Maybe isA() or getType is useful. here is my logical code:
> 
> if (item is CanvasEllipse)
>   do something
> else if (item is CanvasPolygon)
>   do something different
> else
>   do other things
> 
> Anyone can translate the code to gnomemm code? thanks! I get stuck here

Why do you need to know "before dynamic_cast"? Maybe you don't understand how
to use dynamic_cast<>. Your pseudo-code would become C++ like so:

if( dynamic_cast<Gnome::Canvas::Ellipse*>(pItem) )
{
  //do something
}
else if( dynamic_cast<Gnome::Canvas::Polygon*>(pItem) )
{
  //do something else
}


Murray Cumming
murrayc usa net
www.murrayc.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]