Error no suitable constructor exists

I've got a function that returns the object that is being checked. It is giving me an error telling me that I do not have a copy constructor. I do have two constructors. I'm not sure why I'm getting this error. I've got to get this done today. I'd appreciate any help.

Code that calls object
1
2
3
	StateData temp = HTable[hashIndex];
	rec = temp.getStateData(n, sfound);


Function that returns the object
1
2
3
4
5
6
7
8
9
10
	StateData StateData::getStateData(string n, bool &found)
	{ 
			if (name == n)
			{
				found = true;
				return this;  //here is where I get the error
			}
	}



Constructors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
	StateData::StateData()
	{
		name = " ";
		capitol = " ";
		yearAdmit = 0;
		order = 0;
	}

	StateData::StateData(string n, string c, int y, int o)
	{
		name = n;
		capitol = c;
		yearAdmit = y;
		order = o;
	}
Line StateData temp = HTable[hashIndex]; copies object in HTable[hashIndex];
However you didn't declare copy constructor for StateData class.
Its signature: StateData::StateData(const StateData& from)
Without it compliler does not know, how to construct your object.
Last edited on
here is where I get the error
return this; returns the pointer to the object.

To return the object itself write

return *this; // Note: *
Thanks!
Topic archived. No new replies allowed.