leoni 0 Newbie Poster

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!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.