Overload the assignment operator in C++ [duplicate] - c++

This question already has answers here:
C++ assignment operator - compiler generated or custom?
(5 answers)
Closed 7 years ago.
I have a general question i C++ that I coudln't get a clear answer to and I'm hoping I get an answer to it here. As a programmer, do I need to explicitly overload the assignment operator for a class when all instance data fields in this class are standard built in C++ data types.

No. You only need to overload the defaults if you are doing manual resource management. If all of your members can be treated as POD types then you will be fine.

No, you don't.​​​​​​​​​​​​​​​​​​​​​

Related

In c++ why we can overload `operator ->` and can't overload `operator .` [duplicate]

This question already has answers here:
Why can't you overload the '.' operator in C++?
(4 answers)
Closed 5 years ago.
In c++, why we can overload operator -> and can't overload operator .?
Similarly, why we can overload operator ->* and can't overload operator .*?
I will be appreciated if you can help me!
Stroustrup actually has this as an FAQ question on his website. To quote his answer:
Operator . (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading . or an object referred to by .
This problem can be solved in several ways. At the time of standardization, it was not obvious which way would be best
(Note that Stroustup himself has since proposed allowing overloading of operator., as have others, so we may see it in a future version of the language.)

Why can't a ternary operator be overloaded? [duplicate]

This question already has answers here:
Why is it not possible to overload the ternary operator?
(6 answers)
Closed 5 years ago.
I was always curious about that, but never found a solid answer or an easy to understand explanation. I have tried with other operators and it works just fine. This operator in particular is an interesting one. I just can't get my head wrap around it.
FAQ of stroustrup :
There is no fundamental reason to disallow overloading of ?:. I just
didn't see the need to introduce the special case of overloading a
ternary operator. Note that a function overloading expr1?expr2:expr3
would not be able to guarantee that only one of expr2 and expr3 was
executed.

How to overload -> operator in C++ [duplicate]

This question already has answers here:
Overload -> operator to forward member-access through Proxy
(3 answers)
Overloading member access operators ->, .*
(5 answers)
Closed 8 years ago.
As per the title, how to overload -> operator in C++?
I can't find any documentation.
cppreference glosses over it.
The Wikipedia page on overloading similarly glosses over it.
Operator overloading <-- this SO post again has a '->' shaped hole in it, although one comment gives a hint:
operator->() is actually extremely weird. It's not required to return
a value_type* -- in fact, it can return another class type, provided
that class type has an operator->(), which will then be called
subsequently. This recursive calling of operator->()s proceeds until a
value_type* return type occurs. Madness! :)
It appears that this particular operator is not straightforward to overload.
Could someone link to documentation, or (preferably) provide some here?
PS I recognisze this is an unusual overload, I have need of it in a Proxy pattern, here

Which comparison operators are necessary to define or implicitely defined? [duplicate]

This question already has answers here:
What are the basic rules and idioms for operator overloading?
(8 answers)
Closed 9 years ago.
If I define operator== and operator=< all other operators can be logically implied.
Does the compiler handle this for me or do I have to write them on my own?
No it doesn't, you'll have to overload those as well if you plan to use them.
It doesn't even know that a != b is actually !(a==b).
No; the standard would have to assume that you wish for all your operators to follow this branch of mathematics' rules, and it has no right doing that.
However, in some situations, rules like this are used to simplify implementation. For example, the default comparator for std::map keys is std::less — where the underlying tree implementation needs to know whether key A is greater than or equal to key B, the logic is reformed to whether key B is less than A; in this way, only one comparator is required.

finding addressof a object whose ampersand operator is overloaded and private [duplicate]

This question already has answers here:
If an operator is overloaded for a C++ class how could I use a default operator instead?
(3 answers)
Closed 8 years ago.
I have a class which is overloading ampersand(&) operator and made it private. I don't have a latest C++11 compliant compiler so is there any way by which I can get address of my object using current C++ compiler only
Thanks
reinterpret_cast<T *>(&reinterpret_cast<char&>(obj))
Dunno if it's safe though.. (well clearly it's a bit dodgy)
Use the addressof() function from Boost.Utility. If you don't want to use Boost, you can still look at it's implementation which consists of just a single header.