Thursday, July 30, 2009

I need help in the following code?

i create an abstract class "Shape" and i create an array from it i try to do the following steps but the error still





class Shape-----%26gt;abstract


class Circle------%26gt;inheritance from Shape


class Point-------%26gt;inheritance from Shape too





Circle C1;


Point P ( 10 , 20 );








Shape *Array [ 2 ];


Array [ 0 ] = %26amp;C1;-------------%26gt;the error occured here


Array [ 1 ] = %26amp;P; ----------%26gt;and here





the error text is :


cannot convert from 'class Circle *' to 'class Shape *'


Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast





i need any help with "reinterpret_cast" command

I need help in the following code?
You could help us somewhat by including the actual code. The terms aren't quite the ISO standards, so I'm not entirely certain what you've done. I gather that Circle and Point are derived from Shape. This means that they have all the attributes of shape, but may have more. This would be why the complier doesn't want to covert back to the base type.





I believe you're doing this in the wrong direction. What you need is a more *inclusive* class, derived from Shape and Circle. Use virtual classes, and I think you may get what you need. If not, please re-post and include the actual code, so we're not guessing about what you did.

garden design

No comments:

Post a Comment