Sign in to follow this  

Comile Error: C2784

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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 ) ...".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 argument
for '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.

Share this post


Link to post
Share on other sites
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)
{
}


Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Okay, adding those comparison operators has sorted out the main errors, but has replaced them with a new one (shown below). What should be a simple error, however, turns out to be a monster as I have already defined an operator to perform the function it needs.

bool LINE::operator<(const LINE &LineB)
{
return (false);
}
/*
C:\Program Files\Programming\DevStudio\VC\INCLUDE\xutility(45) :
error C2678: binary '<' : no operator defined which takes a left-hand
operand of type 'const class LINE' (or there is no acceptable conversion)
*/


I think im closer to resolving this, though. Thanks for your input everyone now lets see if I can clear this final hurdle!

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
Well, see the error, it wants a const LINE. It seems like the problem is elsewhere.


The error is not elsewhere.

It wants to be able to call LINE::operator< on a const object. operator< needs to be specified as const:

bool LINE::operator<(const LINE& rhs) const

Share this post


Link to post
Share on other sites
Guys, yer geniuses. All problems sorted. Its a rather hack-around way to do something reasonably simple but as long as it works, im happy. Code compiles and does what it is intended to do. Thanks for your help everyone.

Share this post


Link to post
Share on other sites

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this