I started to do some reading about template, found interesting example
template <class T1, class T2>
bool GetItUP (T1 a, T2 b)
{
return (a>b?a:b);
}
And the way to use it:
int _tmain(int argc, _TCHAR* argv[])
{
int a = 20;
float b = 23.90;
GetItUP<int,float>(a,b);
return 0;
}
So curios enough I tried to do something like that:
template <typename T1, typename T2>
void ShowMeMap(map<T1, T2>* myTempMap, string _text, bool bIsDigit)
{
int currentSize = (*myTempMap).size();
if (bIsDigit)
{
string temp = "AddedNewOne";
typedef pair<int, string> ins_pair;
(*myTempMap).insert(ins_pair(10,"NewValueInserted"));
}
else
{
//list<string> tempList ;
//tempList.push_back("Add_1");
//tempList.push_back("Add_2");
//tempList.push_back("Add_3");
//typedef pair<int, list<string>> pairTempMap;
//(*myTempMap).insert(pairTempMap(12,&tempList));
//(*myTempMap)[currentSize] = tempList;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
map<int,list<string>> myComplicatedMap ;
map<int,string> myMap ;
typedef pair<int, list<string>> pairTempMap;
myMap[0] = "Starts";
myMap[1] = "ToShow";
myMap[2] = "Values";
list<string> textList;
textList.push_back("One");
textList.push_back("Two");
textList.push_back("Three");
textList.push_back("Four");
myComplicatedMap.insert(pairTempMap(1,textList));
ShowMeMap<int,string>(&myMap, "Text_Test",true);
// compiler error
//ShowMeMap <int,list<string>>(&myComplicatedMap, "Text_Teste2",false);
return 0;
}
Try to compile I got the following:
error C2664: 'std::list<_Ty>::list(const std::allocator<_Ty> &)' : cannot convert parameter 1 from 'const std::string' to 'const std::allocator<_Ty> &' c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility
It will be the same error if I do just like that as well:
ShowMeMap (&myComplicatedMap, "Text_Test2",false);
return 0;
}
What I’m missing here? Can it be corrected? Is there work around (besides to make another template function)?
Regards