Do you have a trouble to find 'virtual assignment operator'? You can find your answers here.
Essential assignment It is possible to brand the assignment wheeler dealer virtual. However, dissimilar the destructor case where virtualization is always a skilful idea, virtualizing the assignment operator actually opens up A bag full of worms and gets into some in advance topics outside of the scope of this tutorial.
Table of contents
- Virtual assignment operator in 2021
- Virtual operator c++
- Assignment operator in c++
- C++ implement assignment operator
- Define assignment operator
- Virtual comparison operator c++
- Virtual operator
- C++ object assignment operator
Virtual assignment operator in 2021
Virtual operator c++
Assignment operator in c++
C++ implement assignment operator
Define assignment operator
Virtual comparison operator c++
Virtual operator
C++ object assignment operator
What's the point of making an assignment operator virtual?
It depends on the operator. The point of making an assignment operator virtual is to allow you from the benefit of being able to override it to copy more fields. So if you have an Base& and you actually have a Derived& as a dynamic type, and the Derived has more fields, the correct things are copied.
Can a call be a virtual function in D?
So even though in the following example, operator= is made virtual, the call will never act as a virtual function in D, because the parameters and return value of operator= are different. The function B::operator= (const B& right) and D::operator= (const D& right) are 100% completely different and seen as 2 distinct functions.
Why is operator = not a virtual function?
A function's signature needs to be the same for virtual to come into play. So even though in the following example, operator= is made virtual, the call will never act as a virtual function in D, because the parameters and return value of operator= are different.
Can you use RTTI to handle virtual functions?
You can use RTTI to properly handle virtual functions that take in your type. Here is the last piece of the puzzle to figure out how to properly handle assignment when dealing with possibly inherited types. It depends on the operator.
Last Update: Oct 2021