Comile Error: C2784

Started by
14 comments, last by Neo Genesis10 19 years, 1 month ago
I've hit the end of my rope with this error. Its caused (somehow) by my overloaded = operator. It reports the error in xutility and the nature of the error suggests its something to do with the fact im using vectors as a previous bug-fix reports this error is quite common when dealing with them (Source MSDN). However, the bug-fix was sorted in VC++ 97 and I am using VC++ Version 6, an even later version. Here's the code for my overloaded operator. Hopefully an eagle-eyed coder can spot something which I have overlooked.

// The offending operator

LINE LINE::operator=(const LINE LineB)
{
	this->text = LineB.text;
	return (*this);
}

// The following variable is a member of another class.

vector <LINE> LineSetA;
Thanks in advance.
Worship the holy trinity that is Blitz, Babes and Beers!
Advertisement
It would be a lot easier to figure out what is causing your error if you said what "the error" is.

I doubt this is the answer, but the parameter to the function needs to be "const LINE & LineB". Check the parameter to your copy constructor for the same problem.

Also, in order to handle the statement "x = x;", operator=() usually has something like this: "if ( this != &LineB ) ...".
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Error C2784 is:


error C2784: '(template instantiation) : could not deduce template argument for (a template) from (a class)'.

Don't know what to fill in though.
Thanks John, overlooked that mistake. Still getting the template problems though. If I take out the overloaded operator, everything compiles as it should. But I need that operator for some of the functions I've yet to include.
Worship the holy trinity that is Blitz, Babes and Beers!
Hi,

How's LINE defined, because it looks an awful lot like a macro of some kind, but that could be your naming convention too. [wink]

Is class/struct LINE templated and if so: how?

cu,
CipherCraft
Can we see the declaration of your LINE class/struct, and also the full error message, and the line of code that the error occurs on?
class LINE{	private:     	std::string parseit(  char c ); 	public:            	std::string text;	//constructor / destructor       	LINE();	~LINE();	void init(LINE line);	int size();	std::string fromstring( char c );	LINE operator=(const LINE &LineB);};// Error supplied/*C:\Program Files\Programming\DevStudio\VC\INCLUDE\xutility(45) : error C2784:'bool __cdecl std::operator <(const class std::basic_string<`template-parameter-1',`template-parameter-2',`template-parameter-3'> &,const template-parameter-1 *)' : could not deduce template argumentfor 'const class std::basic_string<`template-parameter-1',`template-parameter-2',`template-parameter-3'> &'from 'const class LINE'*/
Actually, thats one of 24 errors, each one detailing pretty much the same error, but given for a different template.
Worship the holy trinity that is Blitz, Babes and Beers!
Translation of that error: "Something to do with operator < (probably to do with sorting) is expecting a std::string, but it's getting a LINE instead."

Try making a copy constructor. The STL might be complaining because you don't have one, but you do have an operator=()
Something like:
LINE::LINE(const LINE& rhs) : text(rhs.text){}
Yes, it is indeed something to do with the < operator. It always occurs where the comparison (*_F1 < *_F2) is made in xutility. I can only assume that F1 and F2 are pointers due to my lack of knowledge on the file. If so, then surely this would not prove to be a problem for the compiler?
Worship the holy trinity that is Blitz, Babes and Beers!
I'm confused. I don't get any compile errors no matter which compiler I use (I tried VC++ 6.00.8168, Borland C++ 5.5.1, Mingw GCC 3.2.3, Visual C++ .NET 2003).

Quote:I can only assume that F1 and F2 are pointers due to my lack of knowledge on the file. If so, then surely this would not prove to be a problem for the compiler?


Not always. _F1 and _F2 ([wow], that code is ugly [grin]) are input iterators (pointers, usually, but not always). The error is in the function lexicographical_compare. As far as I can see this is called from std::vector<_Ty, _A>::_Lt which is called when a vector is compared with another vector of the same type.

Try defining comparison operators for your class. (Although this shouldn't be necessary).

This topic is closed to new replies.

Advertisement