R
Richard E Collins
I coded up a nice little base class that I wanted to inherit of anytime I
wanted a class to become part of a linked list. It all worked except from
one problem. The GetNext function returned a pointer to the next object but
this pointer was of the bass calls type and when I cast it the overall class
type the pointer did not change as so was now invalid. The only way I got
round it was to a have a void pointer that all the derived classes set to
their this and returned it in the GetNext function. This works but just
feels like a hack.
What I need to know is....
class a
{
int data;
public:
cool functions.
}
class b : public a
{
int more_data;
public:
more funcs
};
if a have a pointer to 'a' when 'a' is really a 'b' how can I cast it to
'b'. ?
Is going to be a runtime op and not a compile time one?
wanted a class to become part of a linked list. It all worked except from
one problem. The GetNext function returned a pointer to the next object but
this pointer was of the bass calls type and when I cast it the overall class
type the pointer did not change as so was now invalid. The only way I got
round it was to a have a void pointer that all the derived classes set to
their this and returned it in the GetNext function. This works but just
feels like a hack.
What I need to know is....
class a
{
int data;
public:
cool functions.
}
class b : public a
{
int more_data;
public:
more funcs
};
if a have a pointer to 'a' when 'a' is really a 'b' how can I cast it to
'b'. ?
Is going to be a runtime op and not a compile time one?