T
Timothy Stark
Hello folks,
I am trying get operator + working. I developed a class for a pair (left
and right values).
class Word10 {
public:
uint18 left, right;
:
:
inline Word10& operator += (const Word10& val)
{
if ((right += val.right) & H10_MASK)
(right &= H10_MASK, left++);
left = (left + val.left) & H10_MASK;
return *this;
}
};
inline Word10& operator + (const Word10& x, const Word10& y)
{ return Word10 (x) += y; }
:
:
Word10 x(2, 2), y(3, 3), z;
z = x + y;
cout << "Z = (" << z.left << "," << z.right << ")" << endl;
I tried to print but it did not work. It crashed with segmentation fault or
incorrect result of sum (scrambled results). However, it works so well with
using += operator. Does anyone have resolve the problem with that? I am
using GCC C/C++ compiler.
Thank you!
Tim
I am trying get operator + working. I developed a class for a pair (left
and right values).
class Word10 {
public:
uint18 left, right;
:
:
inline Word10& operator += (const Word10& val)
{
if ((right += val.right) & H10_MASK)
(right &= H10_MASK, left++);
left = (left + val.left) & H10_MASK;
return *this;
}
};
inline Word10& operator + (const Word10& x, const Word10& y)
{ return Word10 (x) += y; }
:
:
Word10 x(2, 2), y(3, 3), z;
z = x + y;
cout << "Z = (" << z.left << "," << z.right << ")" << endl;
I tried to print but it did not work. It crashed with segmentation fault or
incorrect result of sum (scrambled results). However, it works so well with
using += operator. Does anyone have resolve the problem with that? I am
using GCC C/C++ compiler.
Thank you!
Tim