Template puzzle question

I started to do some reading about template, found interesting example
1
2
3
4
5
template <class T1, class T2>
bool GetItUP (T1 a, T2 b) 
{
   return (a>b?a:b);
}

And the way to use it:
1
2
3
4
5
6
7
8
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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:
1
2
3
   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
Why is ShowMeMap() a template function if line 8 makes assumptions about what T1 and T2 are?
Topic archived. No new replies allowed.