I wrote class with template. class has map as member and some getxxx() / setxxx() member functions.
template<typename T1,typename T2>
class C1{
map<T1,T2> M;
public:
map<T1,T2> getM();
T2 getMvalue(T1 Key);
void setM(T1 key,T2 Value);
};
here I want to implement getMvalue(), where it recieves key as argument and returns the corresponding “value” if “key” is available in mapM.
It look something like…
template<typename TKey,typename TValue>
T2 C1<T1,T2>::getMvalue(T1 Key){
if(M.count(Key)>0)
return M[Key];
else
return(???);
};
Here I need to use something in place of ???. keeping in mind that return type of function is T2, which can be anything depending on user decision.
How can i replace “???” and with what?
I would encourage you to use the
TryGetpattern