anyways i been trying to find somewhere on the internet that can help me overload %= and % operators.
any help would be much thanked
Printable View
anyways i been trying to find somewhere on the internet that can help me overload %= and % operators.
any help would be much thanked
Just use "operator%"..you can then overload it for what types you want to use modulus with....like so
Code:#include <iostream>
class MyClass{
public:
void Set(int i){m_x = i;}
operator%(const MyClass& mc){return m_x % mc.m_x;}//for Myclass
operator%(int i){return m_x % i;}//For Ints
protected:
int m_x;
};
int main( void )
{
MyClass x,
y;
x.Set(100);
y.Set(9);
std::cout << "x%y = " << x % y << std::endl;
std::cout << "x%13 = " << x % 13 << std::endl;
return 0;
}
Thanks very much!
for some reason its been like a nightmare since computer science in high school ... i could do everything else but modulus :P.
Well thanks again!!!
-chris