help with operator%

A

Al-Burak

In the program
--- money.hpp
namespace jme{
class Money{
protected: float amount;
...
public: friend jme::Money jme::eek:perator%( jme::Money&,
jme::Money&);
};
}
--- money.cpp
jme::Money jme::eek:perator%(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::eek:perator%(jme::Money&,
jme::Money&)':
money.cpp:72: error: invalid operands of types `float' and `float' to
binary `operator
 
G

GB

Al-Burak said:
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
 
M

Mike Wahler

Al-Burak said:
In the program
--- money.hpp
namespace jme{
class Money{
protected: float amount;
...
public: friend jme::Money jme::eek:perator%( jme::Money&,
jme::Money&);
};
}
--- money.cpp
jme::Money jme::eek:perator%(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::eek:perator%(jme::Money&,
jme::Money&)':
money.cpp:72: error: invalid operands of types `float' and `float' to
binary `operator

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

-Mike
 
Z

zikaizhang

Al-Burak wrote:
[slit]
--- money.cpp
jme::Money jme::eek:perator%(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]
 
M

Mike Wahler

Greg Comeau said:
[QUOTE="GB said:
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.[/QUOTE]

Is not 'enum' an integral type?

-Mike
 
G

Greg Comeau

Greg said:
Mike said:
[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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top