-
April 2nd, 2010, 07:22 AM
#1
error C2440 using adjacent_difference stl template function
Hi all,
I would like to use STL <numeric> adjacent_difference function in my program but I'm getting the error:
1>c:\program files\microsoft visual studio 8\vc\include\numeric(349) : error C2440: '=' : cannot convert from 'Csimple' to 'int'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called.
I have a <list> of Csimple's (udt) objects where I would calculate the differences (Csimple is a very simple class with only one int parameter called "firstInt").
list<Csimple> simpleList;
simpleList.push_back(Csimple(10)); //fill the list with Csimple's objects
...
simpleList.push_back(Csimple(25));
vector<int> res(simpleList.size());
vector<int>::iterator v_resItr;
v_resItr = adjacent_difference(simpleList.begin(), simpleList.end(), res.begin());
I've also added the overloaded version of operator- and operator= as class members as suggest by errors provided by compiler
Csimple Csimple:perator -(Csimple op2)
{ return firstInt - op2.firstInt; }
Csimple Csimple:perator =(Csimple op2)
{ return firstInt = op2.firstInt; } //I'm not sure about the returned type, should be it an int?
I assume that I can use adjacent_difference also with user-defined type rather than just int; may be my assumption wrong?
Can someone help me, pls?
Many thanks in advance
-
April 2nd, 2010, 07:28 AM
#2
Re: error C2440 using adjacent_difference stl template function
Code:
Csimple Csimple :: operator -(Csimple op2)
{ return firstInt - op2.firstInt; }
Csimple Csimple :: operator =(Csimple op2)
{ return firstInt = op2.firstInt; }
Both return a 'int', not a 'Csimple'
-
April 2nd, 2010, 07:57 AM
#3
Re: error C2440 using adjacent_difference stl template function
Hi Skizmo,
many thanks for your suggestion, now is a little bit better because I got just 1 errors C2440 (before was 2).
int Csimple :: operator -(Csimple op2)
{ return firstInt - op2.firstInt; }
int Csimple :: operator =(Csimple op2)
{ return firstInt = op2.firstInt; }
I need to change just the return type or the parameter type as well?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|