954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Strange Behevior when trying to create a Template containing maps

Hi all, i'm new to Templates and when i tried to implement templates methods which needs to use a map (which is a member in private), the map can only do 3 things: insert, swap, and operator =. and i don't get the full functionality of map..

Here's the code:

#ifndef __GARAGE_H_
#define __GARAGE_H_
#include <map>
using namespace std;
template <class T,class SortKey, class SearchKey>
class GarageDataBase
{
public :

	GarageDataBase();
	virtual ~GarageDataBase();	
    const T& Top() const;
	bool Add(T data,SortKey key2, SearchKey key2);
	T Remove(SearchKey toRemove);
	T Find(SearchKey toFind) const;
	bool isEmpty()const;
	


private:
	multimap<SortKey,T> firstMap;
	multimap<SearchKey,pair<SortKey,T>*> secondMap;

};
#endif



template <class T,class SortKey, class SearchKey> GarageDataBase<T,SortKey,SearchKey>::GarageDataBase()
{

}

template <class T,class SortKey, class SearchKey> GarageDataBase<T,SortKey,SearchKey>::~GarageDataBase()
{
}

template <class T,class SortKey, class SearchKey> const T& GarageDataBase<T,SortKey,SearchKey>::Top() const
{
	firstMap.
}


in the last func when trying to get into firstMap mathods, all i get is: insert, swap or, =...


how do i get to "first" or s"econd" in the map?


Thank you and sorry i'm just a beginner here

danalovesc
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

Try using iterators.

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 
template <class T,class SortKey, class SearchKey> const T& GarageDataBase<T,SortKey,SearchKey>::Top() const
{
	mulimap<SortKey,T>::iterator it;
	it=firstMap.
}


still doesn't let me to firstMap.begin()

i want to return the first element in the map

danalovesc
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

What do you mean "doesn't let me"? What happens if you change line 5 above to say

it=firstMap.begin();

?

arkoenig
Master Poster
703 posts since Jun 2010
Reputation Points: 359
Solved Threads: 109
 

it doesn't complete me with Intellisense code completion..

Maybe its the completion system problem?

danalovesc
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

I would not expect code completion to work flawlessly in the presence of templates, because in general it's not possible to know for certain what types are involved. What happens if you enter by hand the statement I suggested and compile it?

arkoenig
Master Poster
703 posts since Jun 2010
Reputation Points: 359
Solved Threads: 109
 

it seems to complie however i still doesn't understand why can't i accsses STL map methods?

danalovesc
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

You can -- you just did.

The trouble is that in general, when the type of an object includes a template parameter, it is not always possible to determine what all of its members are.

arkoenig
Master Poster
703 posts since Jun 2010
Reputation Points: 359
Solved Threads: 109
 

Ok, Thanks for the help!

I'll try using the methods created and update if it actually works

danalovesc
Newbie Poster
12 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: