F
Filimon Roukoutakis
Dear all,
assuming that through a mechanism, for example reflexion, the Derived**
is known explicitly. Would it be legal (and "moral") to do this
conversion by a cast (probably reinterpret would work here)? The
conversion is done for this purpose: I have an
std::map<std::string, Base*>. I want to "associate" Derived* handles to
the stored Base* so when Base* in the map changes (ie points another
address), the Derived* handle outside of the map is updated
automatically to point to the new address also. Actually what I do for
the moment is that I make the association using eg
Map.Associate(std::string name, Derived*&), where Map is a class
containing the mentioned std::map but I guess this is related to the
title of the post (Is Derived*& -> Base*& moral?). This is the only
reason for the conversion, the Derived objects are to be handled only by
the Derived* pointers. Could there be a better solution that I fail to
see? I need to use a polymorphic container because I have several
Derived* types. Thanks,
filimon
assuming that through a mechanism, for example reflexion, the Derived**
is known explicitly. Would it be legal (and "moral") to do this
conversion by a cast (probably reinterpret would work here)? The
conversion is done for this purpose: I have an
std::map<std::string, Base*>. I want to "associate" Derived* handles to
the stored Base* so when Base* in the map changes (ie points another
address), the Derived* handle outside of the map is updated
automatically to point to the new address also. Actually what I do for
the moment is that I make the association using eg
Map.Associate(std::string name, Derived*&), where Map is a class
containing the mentioned std::map but I guess this is related to the
title of the post (Is Derived*& -> Base*& moral?). This is the only
reason for the conversion, the Derived objects are to be handled only by
the Derived* pointers. Could there be a better solution that I fail to
see? I need to use a polymorphic container because I have several
Derived* types. Thanks,
filimon