| | |
Overloaded + operator not working correctly.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
•
•
error C2662: 'getchecking' : cannot convert 'this' pointer from 'const class Account' to 'class Account &'
Conversion loses qualifiers
C++ Syntax (Toggle Plain Text)
temp2 = (savings + right.getchecking()); }
•
•
Join Date: Feb 2008
Posts: 12
Reputation:
Solved Threads: 0
Ah, I see what you mean. Well, checking goes through two classes, Customer, as well as Accounting, but getchecking shouldn't be trying to change anything.
I am checking back through, but I don't really see anything that would be causing that.
Nor can I figure out why I am getting those weird numbers.
The code is a bit to long to post it all here, which was why I was only showing parts of it.
I am completely stuck.
I recompiled the code so I could get one of the rrors. If I use the code I posted above [to add the values]
I get a few errors like this
class std::basic_string<_E,_Tr,_A> __cdecl std::operator +(const class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'const class std::
basic_string<_E,_Tr,_A> &' from 'class Customer'
I am checking back through, but I don't really see anything that would be causing that.
Nor can I figure out why I am getting those weird numbers.
The code is a bit to long to post it all here, which was why I was only showing parts of it.
I am completely stuck.
I recompiled the code so I could get one of the rrors. If I use the code I posted above [to add the values]
C++ Syntax (Toggle Plain Text)
CustMain = Customers[0] + Customers[1];
I get a few errors like this
class std::basic_string<_E,_Tr,_A> __cdecl std::operator +(const class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'const class std::
basic_string<_E,_Tr,_A> &' from 'class Customer'
Last edited by Jaycii; Feb 17th, 2008 at 9:26 pm.
I have to go so I leave with an properly working example of the operator+ and operator=
Hope this helps...Gerard4143
Hope this helps...Gerard4143
C++ Syntax (Toggle Plain Text)
#include <iostream> class number { public: number(int n):num(n) {} ~number() {} number operator+(const number &rhs); number& operator=(const number & rhs); int getitsvalue() const {return num;} void setitsvalue(int val) {num = val;} friend std::ostream& operator<<(std::ostream & out, const number & rhs); private: int num; }; std::ostream& operator<<(std::ostream & out, const number & rhs) { out<<rhs.getitsvalue(); return out; } number& number::operator=(const number & rhs) { if (this == &rhs) return *this; setitsvalue(rhs.getitsvalue()); return *this; } number number::operator+(const number &rhs) { number temp(getitsvalue() + rhs.getitsvalue()); return temp; } int main (int argc, char**argv) { number x(123); number y(234); number ans(0); ans = x + y; std::cout<<"ans->"<<ans<<"\n"; return 0; }
•
•
Join Date: Feb 2008
Posts: 12
Reputation:
Solved Threads: 0
Thank you for your help. I will look at that while I work on mine.
I also managed to get the other lines of code working, but the values still give the -9.4644e353.
I will post back if I find something else.
--Edit--
Okay, using what you posted above, I get this error:
'class Account __thiscall Account::operator +(const class Account &)' : member function already defined or declared
It is saying its already been defined or declared, but it hasn't.
I also managed to get the other lines of code working, but the values still give the -9.4644e353.
I will post back if I find something else.
--Edit--
Okay, using what you posted above, I get this error:
'class Account __thiscall Account::operator +(const class Account &)' : member function already defined or declared
It is saying its already been defined or declared, but it hasn't.
Last edited by Jaycii; Feb 17th, 2008 at 9:51 pm.
As an earlier inquiry, I was wondering where the savings variable is defined on this one.
Is it part of the Account class?
Is it part of the Account class?
C++ Syntax (Toggle Plain Text)
Account Account::operator+(const Account &right) { Account temp; int temp2; temp2 = (savings + right.getchecking()); temp.setTotalBalance(temp2); return temp; }
"I like beating by head against the wall because it feels so good when I stop"
•
•
Join Date: Feb 2008
Posts: 12
Reputation:
Solved Threads: 0
I can't seem to edit my post anymore. Well, after going back through my code, I fixed part of the problem. [I can now add the values outside of the function I am calling]. But now all my values inside of that function are using numbers like the -9.5948e495.
Thanks for all the help. Going to try to see if I can fix this problem now.
--edit---
It was my = operator the entire time. Once I fixed it, everything was fine.
Thanks for all the help. Going to try to see if I can fix this problem now.
--edit---
It was my = operator the entire time. Once I fixed it, everything was fine.
Last edited by Jaycii; Feb 18th, 2008 at 12:28 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: How to delete files from a direct pathway?
- Next Thread: simple question regarding array
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





