Why can I not use operator overloading for classes?
Date : March 29 2020, 07:55 AM
|
What if -> operator do not return the reference like dot . operator? Will this stop overloading -> operator as wel
Tag : cpp , By : Bart van Bragt
Date : March 29 2020, 07:55 AM
it fixes the issue I only understood how overloading the operator-> works, after reading this: struct X { int foo; };
struct Y {
X x;
X* operator->() { return &x; } // returns pointer
};
struct Z {
Y y;
Y& operator->() { return y; } // returns reference
};
Z z;
z->foo = 42; // Works!
|
Overloading operator += with two classes
Date : March 29 2020, 07:55 AM
I hope this helps you . Is there any way to achieve my goal without actually overloading operator+ for class B?
|
Overloading the plus operator for a set of classes
Tag : cpp , By : Picoman Games
Date : March 29 2020, 07:55 AM
|
Arithmetic operator overloading for class template, the operator should take two classes of different types
Tag : cpp , By : user179271
Date : October 06 2020, 04:00 PM
Hope this helps Your overloaded operator+ function takes two const fraction & arguments. The problem is that the two arguments you use are of different type, the T template for each are different. To begin solving it you need to use different types for each argument, which means two template arguments. You also need to have a common type for the returned faction object.template <typename U, typename V>
fraction<std::common_type_t<U, V>> operator+(const fraction<U>& fraction1, const fraction<V>& fraction2)
{
fraction<std::common_type_t<U, V>> temp;
// ...
return temp;
}
|