Czesc,
wie ktosc skad rozbieznosc w danym przykladzie, gdzie mam zdefiniowany operator + orac operatory << i >> jako friend
result = object1 + object2;
std::cout << result;
dziala ok, ale ponizszy przyklad daje error:
std::cout << object1 + object2;
kod:
ostream &operator<<(ostream &out, Object &test) throw(){
out << test.x;
return out;
}
istream &operator>>(istream &in, Object &test) throw(int){
int tmpInt;
in >> tmpInt;
x.set_x(tmpInt);
}
Modulo Modulo::operator+(const Object &test) throw(){
Object result(x + test.x);
return result;
}
error:
error: cannot bind non-const lvalue reference of type ‘Object&’ to an rvalue of type ‘Object’
naliks/throw()/noexcept/
.throw(int)
wywal. Nic nie wnosi. Składnia ta jest oznaczona jakodeprecated
od c++11. W c++17 częściowo usunięta (dokładniej to wsparcie dla niej, jakkolwiek jest to rozumiane). Od c++20 całkowicie usunięta.