M
Markus Keppeler
Hi Together!
In some (partly legacy) code I have member functions like this:
// class Dummy (class of any type).
class XY
{
Dummy *pGetMe( (returns pointer to some
); dummy member orwhatever)
const Dummy *pGetMe( (returns const pointer to some
) const; dummy member or whatever).
}
Since the implementations on both pGetMe's are 100% identically, only
that they use const/non const types/functions, I'd like to merge them.
I cannot implement the non-const version by calling down to the const
one, since at some level it needs to fetch the non-const pointer to
something. Here also some legacy-issues come into, so I cannot
refactor the entire design ;-).
My next thought was to use templates, like
template <class T>
T pGetMe();
, but here I don't know how to deal with the const/non constness of
the member function. Can I add the const/non const based on the type
of T?
any help is appreciated,
Markus
In some (partly legacy) code I have member functions like this:
// class Dummy (class of any type).
class XY
{
Dummy *pGetMe( (returns pointer to some
); dummy member orwhatever)
const Dummy *pGetMe( (returns const pointer to some
) const; dummy member or whatever).
}
Since the implementations on both pGetMe's are 100% identically, only
that they use const/non const types/functions, I'd like to merge them.
I cannot implement the non-const version by calling down to the const
one, since at some level it needs to fetch the non-const pointer to
something. Here also some legacy-issues come into, so I cannot
refactor the entire design ;-).
My next thought was to use templates, like
template <class T>
T pGetMe();
, but here I don't know how to deal with the const/non constness of
the member function. Can I add the const/non const based on the type
of T?
any help is appreciated,
Markus