Help with Multimap and Template

Everytime I try to compile I get the same three errors and I'm not sure why...
1
2
3
4
5
6
7
8
9
10
1
1>Compiling...
1>main_6_4.cpp
1>c:\documents and settings\deathguru\my documents\visual studio 2008\projects\6_4pro\keypair.h(23) : warning C4346: 'std::multimap<keyType,itemType>::iterator' : dependent name is not a type
1>        prefix with 'typename' to indicate a type
1>        c:\documents and settings\deathguru\my documents\visual studio 2008\projects\6_4pro\keypair.h(24) : see reference to class template instantiation 'keyPairMap<keyType,itemType>' being compiled
1>c:\documents and settings\deathguru\my documents\visual studio 2008\projects\6_4pro\keypair.h(23) : error C2146: syntax error : missing ';' before identifier 'mapIterator'
1>c:\documents and settings\deathguru\my documents\visual studio 2008\projects\6_4pro\keypair.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Build log was saved at "file://c:\Documents and Settings\DeathGuru\My Documents\Visual Studio 2008\Projects\6_4Pro\Debug\BuildLog.htm"
1>6_4Pro - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Header File
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef KEYPAIR_H
#define KEYPAIR_H

#include <iostream>
#include <map>
#include <cstdlib>
#include <string>

using namespace std;

template <typename keyType,typename itemType>
class keyPairMap
{

public:
	keyPairMap();
	void insertItemAndKey(keyType key,itemType item);
	void removeItemAndKey(keyType key);
	void displayItemAndKey();

private:
	std::multimap<keyType,itemType> itemKeyPairMap;
	std::multimap<keyType,itemType>::iterator mapIterator;
};

#endif

template <typename keyType,typename itemType> 
keyPairMap<keyType,itemType>::keyPairMap()
{
}


template <typename keyType,typename itemType> 
void keyPairMap<keyType,itemType>::insertItemAndKey(keyType key,itemType item)
{
	int numItemsOfUserEntered=itemKeyPairMap.count(key);
	
	if(numItemsOfUserEntered>0)
	{
		cout<<"Key already used! Please try again!"<<endl;
	}
	else
	{
		itemKeyPairMap.insert(mapIterator,pair<itemType,keyType>(item,key));
	}
}

template <typename keyType,typename itemType> 
void keyPairMap<keyType,itemType>::removeItemAndKey(keyType key)
{
	mapIterator=itemKeyPairMap.find(key);
	itemKeyPairMap.erase(mapIterator);
}

template <typename keyType,typename itemType> 
void keyPairMap<keyType,itemType>::displayItemAndKey()
{
	cout<<"List:"<<endl;

	 for(multimap<itemType,keyType>::iterator myMapIterator =itemKeyPairMap.begin(); myMapIterator!=itemKeyPairMap.end();++myMapIterator)
	 {
		 cout <<"Item:"<<(*myMapIterator).first<<", Key:"<<(*myMapIterator).second << endl;
	 }
}


Main
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
#include "keyPair.h"


using namespace std;

int main()
{
	int options,count=0,intKey;

	string stringItem;

	keyPairMap<int,string> myPair;
	
	cout<<"This program can be used for any item datatype and key datatype!"<<endl
		<<"For this test run string will be the item, and int will be the key!"<<endl;
	
	while(count<1)
	{
		cout<<"\nPlease choose from the following menu options:"<<endl
			<<"(1)Insert Item and Key"<<endl
			<<"(2)Delete Item"<<endl
			<<"(3)Display Items and Keys"<<endl
			<<"(4)Exit Program"<<endl;

		cout<<"\nSelection:";
		cin>>options;

		switch(options)
		{
		case 1:
			cout<<"Please enter a string item and a int key:"<<endl
				<<"\nString Item:";
				cin>>stringItem;
				cout<<"Int Key:";
				cin>>intKey;
			
				myPair.insertItemAndKey(intKey,stringItem);
				break;

		case 2:
			cout<<"Please enter the key of the item you wish to delete:"<<endl
				<<"If you are unsure, display the list first, incorrect entries yield no result"<<endl;

			cout<<"Key:";
			cin>>intKey;

			myPair.removeItemAndKey(intKey);
			break;

		case 3:
			myPair.displayItemAndKey();
			break;

		case 4:
			exit(1);

		}
	}
	return 0;
}
Figured it out...

typename multimap<keyType,itemType> itemKeyPairMap;
typename multimap<keyType,itemType>::iterator mapIterator;
Topic archived. No new replies allowed.