•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,523 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,376 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 705 | Replies: 17 | Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 72
Reputation:
Rep Power: 1
Solved Threads: 9
•
•
•
•
error C2662: 'getchecking' : cannot convert 'this' pointer from 'const class Account' to 'class Account &'
Conversion loses qualifiers
temp2 = (savings + right.getchecking()); }
•
•
Join Date: Feb 2008
Posts: 12
Reputation:
Rep Power: 1
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]
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 8:26 pm.
•
•
Join Date: Jan 2008
Posts: 72
Reputation:
Rep Power: 1
Solved Threads: 9
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
#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:
Rep Power: 1
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 8: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?
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:
Rep Power: 1
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 11:28 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: How to delete files from a direct pathway?
- Next Thread: simple question regarding array


Linear Mode