mike wrote:
thanks, i didn't manage to make it working exactly like you've
described, but it works like this:
imaginary_number add(imaginary_number lhs,imaginary_number rhs)
{
// clever stuff returning result
}
I don't see the problem:
#include <iostream>
#include <string>
struct imaginary_number {
imaginary_number(int x_, int y_ = 0) : x(x_), y(y_) {}
int x;
int y;
};
imaginary_number add(const imaginary_number& lhs,
const imaginary_number& rhs) {
return imaginary_number(lhs.x+rhs.x, lhs.y+rhs.y);
}
std::ostream& operator<<(std::ostream& os, const imaginary_number& im) {
return os << im.x << ", " << im.y;
}
int main() {
imaginary_number im1 = 4;
imaginary_number im2(4,3);
imaginary_number result1(add(im1, im2));
imaginary_number result2 = add(im1, im2);
std::cout << "result1: " << result1 << "\n";
std::cout << "result2: " << result2 << std::endl;
}
Ben Pope
--
I'm not just a number. To many, I'm known as a string...