473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help with operator%

In the program
--- money.hpp
namespace jme{
class Money{
protected: float amount;
...
public: friend jme::Money jme::operator%( jme::Money&,
jme::Money&);
};
}
--- money.cpp
jme::Money jme::operator%(jme::Money& lhs, jme::Money& rhs){
jme::Money tmp;
return tmp = lhs.amount % rhs.amount;
}

I get an error message, that reads:
Project : Money
Compiler : GNU GCC Compiler (called directly)
Directory : c:\money\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: money.cpp
money.cpp: In function `jme::Money jme::operator%(jme::Money&,
jme::Money&)':
money.cpp:72: error: invalid operands of types `float' and `float' to
binary `operator
--------------------------------------------------------------------------------
What am I doing wrong?

Oct 20 '05 #1
8 3897
GB
Al-Burak wrote:
protected: float amount; : return tmp = lhs.amount % rhs.amount; : What am I doing wrong?


You are attempting to use the '%' operator on floats. The operator can
be used only on integral types.

Gregg
Oct 20 '05 #2

"Al-Burak" <ja******@netscape.net> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
In the program
--- money.hpp
namespace jme{
class Money{
protected: float amount;
...
public: friend jme::Money jme::operator%( jme::Money&,
jme::Money&);
};
}
--- money.cpp
jme::Money jme::operator%(jme::Money& lhs, jme::Money& rhs){
jme::Money tmp;
return tmp = lhs.amount % rhs.amount;
}

I get an error message, that reads:
Project : Money
Compiler : GNU GCC Compiler (called directly)
Directory : c:\money\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: money.cpp
money.cpp: In function `jme::Money jme::operator%(jme::Money&,
jme::Money&)':
money.cpp:72: error: invalid operands of types `float' and `float' to
binary `operator
--------------------------------------------------------------------------------
What am I doing wrong?


Your compiler just told you: you're trying to use
an operator with a type for which it's not valid.

-Mike
Oct 20 '05 #3

Al-Burak wrote:
[slit]
--- money.cpp
jme::Money jme::operator%(jme::Money& lhs, jme::Money& rhs){
jme::Money tmp;
return tmp = lhs.amount % rhs.amount;
try fmod from <math.h>
double fmod(double x, double y);

return tmp.amount = fmod(lhs.amount, rhs.amount);
}

I get an error message, that reads:
Project : Money
Compiler : GNU GCC Compiler (called directly)

[slit]

Oct 20 '05 #4
In article <f6D5f.1445$mV4.1167@dukeread02>, GB <gb@invalid.invalid> wrote:
Al-Burak wrote:
protected: float amount;

:
return tmp = lhs.amount % rhs.amount;

:
What am I doing wrong?


You are attempting to use the '%' operator on floats. The operator can
be used only on integral types.


.... and enum's.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 20 '05 #5

"Greg Comeau" <co****@panix.com> wrote in message
news:dj**********@panix1.panix.com...
In article <f6D5f.1445$mV4.1167@dukeread02>, GB <gb@invalid.invalid>
wrote:
Al-Burak wrote:
protected: float amount;

:
return tmp = lhs.amount % rhs.amount;

:
What am I doing wrong?


You are attempting to use the '%' operator on floats. The operator can
be used only on integral types.


... and enum's.


Is not 'enum' an integral type?

-Mike
Oct 21 '05 #6

Mike Wahler wrote:
"Greg Comeau" <co****@panix.com> wrote in message
news:dj**********@panix1.panix.com...
In article <f6D5f.1445$mV4.1167@dukeread02>, GB <gb@invalid.invalid>
wrote:
Al-Burak wrote:
protected: float amount;
:
return tmp = lhs.amount % rhs.amount;
:
What am I doing wrong?

You are attempting to use the '%' operator on floats. The operator can
be used only on integral types.


... and enum's.


Is not 'enum' an integral type?


No, an enum is not an integral type - although an enum may convert to
an integer value.

Greg

Oct 21 '05 #7
In article <de*****************@newsread3.news.pas.earthlink. net>,
Mike Wahler <mk******@mkwahler.net> wrote:

"Greg Comeau" <co****@panix.com> wrote in message
news:dj**********@panix1.panix.com...
In article <f6D5f.1445$mV4.1167@dukeread02>, GB <gb@invalid.invalid>
wrote:
Al-Burak wrote:
protected: float amount;
:
return tmp = lhs.amount % rhs.amount;
:
What am I doing wrong?

You are attempting to use the '%' operator on floats. The operator can
be used only on integral types.


... and enum's.


Is not 'enum' an integral type?


Not in C++, but can be _promoted_ to one.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 27 '05 #8
In article <ma*******************************************@gnu .org>,
Simon Buchan <si***@hand-multimedia.co.nz> wrote:
Greg wrote:
Mike Wahler wrote:
"Greg Comeau" <co****@panix.com> wrote in message
news:dj**********@panix1.panix.com...
[enum is not an integral]
Is not 'enum' an integral type?

No, an enum is not an integral type - although an enum may convert to
an integer value.

enum is intergral, but not an integer, to be somewhat ambiguously precise.


Ambiguously precise? :)
Anyway, that's not so, so it's ambiguously imprecise :)
I suspect you're cross breading some terms with C previsely ambiguously.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 27 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: KK | last post by:
Hi, im working on this bigInt class. Need help writing algorithm for the operator*, andy help will be appreciated. Thanks in advance bigInt.h...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
15
by: Buck Rogers | last post by:
Hi guys! Task 1: Write a program which presents a menu with 5 options. The 5th option quits the program. Each option should execute a system command using system(). Below is my humble...
11
by: Zilla | last post by:
I have the following simple program. I just want to be able to do math operations (+, -, =)on Timer sublcasses, but want to handle cases where either rhs or lhs is an intrinsic value, However, the...
2
by: cJ500 | last post by:
I can't figure out the problem with this code. I'm using a Borland compiler. The problem is with the / operation overload. When I call isNeg it doesn't output true or false. Now I know this code...
5
by: Samik2003 | last post by:
Hello, The problem is my query is not extracting the correct xml data from the database : Is there something which I am missing?? ANy help would be appriciated. Thanks, Sam. THis is the...
1
by: anumliaqat | last post by:
hello!!! I am new to this site.can anyone help me in my program.It is of rational number class in c++ having operator overloading.It is not executing and i am not able to find mistakes. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.