You pass value intHolderby value. This means that the function acts on the local copy, so there is no effect on the caller’s side. You need to pass the link:
void addToOtherInt(intHolder& other) { other.addToInt(i); }
^
, , , , , , ,
intHolder a = 5;
intHolder b = 10;
intHolder c = a + b;
c += 42;
a = 42 - b;
.. . .
, "" ostream& operator<<, , , , std::cout. :
struct Foo
{
int i;
};
std::ostream& operator<<(std::ostream& o, const Foo& f)
{
return o << f.i;
}
Foo f;
std::cout << f;
std::cerr << f;
std::ofstream tmp("foo.txt");
tmp << f;