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

Problems using stl:map

Hi all!!

I'm using stl map to store some data here is the example:

struct MapKey
{
	int i, j;

	void Set(int pI, int pJ)
	{
		//this guarantee that i is always lesser than j
		if (pI < pJ)
		{
			i = pI;
			j = pJ;
		}
		else
		{
			j = pI;
			i = pJ;
		}
	}

	MapKey(int pI, int pJ)
	{
		Set(pI, pJ);
	}

	MapKey()
	{
		//DO NOTHING
	}

	bool operator<(const MapKey &pOther) const
	{
		return(i < pOther.i) || ((i == pOther.i) && (j < pOther.j));
	}

	bool operator==(const MapKey &pOther) const
	{
		return (i == pOther.i) && (j == pOther.j);
	}

};
template <int Dim>
struct Pair
{
	double w;    //kernel value
	double dw;   //kernel derivative value
	double dist; //distance between particles
	Particle<Dim> * iPart;	//pointer to the first particle
	Particle<Dim> * jPart;  //pointer to the secound particle

	Pair()
	{
		//DO NOTHING
	}

	Pair(const Pair &pOther)
	{
		w = pOther.w;
		dw = pOther.pw;
		dist = pOther.dist;
		iPart = pOther.iPart;
		jPart = pOther.jPart;
	}
};


In the main program:

map<MapKey, Pair<Dim> > pairs;
Pair<Dim> tmpPair;
MapKey tmpKey;

//tmpKey and tmpPair are set to some value, code is not shown here

pairs.insert(pair<MapKey, Pair<Dim>>(tmpKey, tmpPair));


this code gave me the fallowing error in the last line:error: ‘tmpKey’ cannot appear in a constant-expression.

I can not imagine why is this happening.
any help will be really appreciated.
Thanks in advance!!!

leoni
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You