E
Ex_Ottoyuhr
Given a situation in which someone has, say:
class Foo { ... }
class Bar: public Foo { ... }
class Baz: public Foo { ... }
class Bindi: public Baz { ... }
and later in the code:
Bindi somebody;
Foo* aPtr = &somebody;
std::vector<Foo*> somePtrs;
somePtrs.push_back(aPtr);
(and manipulations of them)
is there any legal way to get from somePtrs to somebody? That is, is
it possible, in this case, to take a pointer to a base class, say Foo,
and convert it to a pointer to a derived class several levels below,
say Bindi, and get meaningful data (assuming the Foo pointer really
does point to a Bindi)?
I'm working on a program wherein the only means to get a pointer to an
object of any member of a particular inheritance hierarchy is to get a
pointer to the root of that hierarchy out of a linked list.
Unfortunately, as I've just discovered (and should have realized much
sooner), several child classes have functions that would be completely
pointless outside of themselves (ruling out adding them to the base
class), but are vital to the child class' operation. So far, I've
tried all sorts of dangerous ideas -- static casting, dynamic casting,
even reinterpret-cast -- but the former two were illegal and the last
turned up gibberish. Is there any way to get at these member functions
without rewriting the code to use pointers to the child classes? I've
been working on this thing for _quite_ some time, and it would involve
rewrites of a substantial codebase...
I'm running Visual Studio .NET 2003, if it helps.
class Foo { ... }
class Bar: public Foo { ... }
class Baz: public Foo { ... }
class Bindi: public Baz { ... }
and later in the code:
Bindi somebody;
Foo* aPtr = &somebody;
std::vector<Foo*> somePtrs;
somePtrs.push_back(aPtr);
(and manipulations of them)
is there any legal way to get from somePtrs to somebody? That is, is
it possible, in this case, to take a pointer to a base class, say Foo,
and convert it to a pointer to a derived class several levels below,
say Bindi, and get meaningful data (assuming the Foo pointer really
does point to a Bindi)?
I'm working on a program wherein the only means to get a pointer to an
object of any member of a particular inheritance hierarchy is to get a
pointer to the root of that hierarchy out of a linked list.
Unfortunately, as I've just discovered (and should have realized much
sooner), several child classes have functions that would be completely
pointless outside of themselves (ruling out adding them to the base
class), but are vital to the child class' operation. So far, I've
tried all sorts of dangerous ideas -- static casting, dynamic casting,
even reinterpret-cast -- but the former two were illegal and the last
turned up gibberish. Is there any way to get at these member functions
without rewriting the code to use pointers to the child classes? I've
been working on this thing for _quite_ some time, and it would involve
rewrites of a substantial codebase...
I'm running Visual Studio .NET 2003, if it helps.