G
Gonçalo Rodrigues
Hi all,
(note: newbie alert)
Suppose you have a hierarchy of objects that you deal with via smart
pointers, e.g. something like:
template<typename T>
class Ref {
private:
T* ptr;
<etc..>
};
Now suppose also that the hierarchy is singly-rooted and call the root
class Object. Most of the times a smart pointer to Object is all that
you will ever need, but there are times when you need have a smart
pointer to a derived class, so what is the best way to write the Ref
template so that it reflects the single-rootedness of the hierarchy?
My best up to now is
class Ref {
private:
Object* ptr;
<etc...>
};
template<typename T>
class PRef : public Ref {
private:
T* ptr;
<etc...>
};
But this is far from optimal. Any ideas?
TIA, with my best regards,
G. Rodrigues
(note: newbie alert)
Suppose you have a hierarchy of objects that you deal with via smart
pointers, e.g. something like:
template<typename T>
class Ref {
private:
T* ptr;
<etc..>
};
Now suppose also that the hierarchy is singly-rooted and call the root
class Object. Most of the times a smart pointer to Object is all that
you will ever need, but there are times when you need have a smart
pointer to a derived class, so what is the best way to write the Ref
template so that it reflects the single-rootedness of the hierarchy?
My best up to now is
class Ref {
private:
Object* ptr;
<etc...>
};
template<typename T>
class PRef : public Ref {
private:
T* ptr;
<etc...>
};
But this is far from optimal. Any ideas?
TIA, with my best regards,
G. Rodrigues