To provide two (or more) functions that perform similar, closely related
things, differentiated by the types and/or number of arguments it
accepts. In some cases it’s worth arguing that a function of a different
name is a better choice than an overloaded function. In the case of
constructors, overloading is the only choice.
override is used in inheritance, child class will override baseclass virtual
function. override is a C++11 keyword used to override base virtual
method: some times a programmer doesn’t know whether he is overriding or
whether he is creating a new virtual method with a different signature.
overwrite is not standard conception in C++, most time, you can call it
name hiding. There are two things: The first one is If you redefine the same
name non virtual function in both base and child classes, you can’t use
dynamic binding, just static binding.
If you try to Overload base member function. "Name hiding" will
happen. Overloading just happens in the same class, not in thehierarchyAny same name is base class will not visible in derived class. You
can use using keyword to add it in your derived class. Then It will compile
If there is a value that you can use for a default, use default parameter.
Why << need to be friend? You need to consider: Beccause you need to write
cout« obj. If you declare « as a member operator, you have to write
obj«cout; it looks weird.
If you want to overload + operator, and support time t; 3+t; Previous
method can’t be work. You need to define a friend function. In order to
improve a t+3 efficiency, you also can define a member function time
operator+(int i) member function.
ob = ob1+ob2 will changed to: ob1.operator+(ob2); so, it should be
defined as the first const to avoid ob1+obj2= ob3, the last const
make the ob to invoke this operator doesn’t change the value in this
class.
assignment operator overload. 1) return a non-const reference, and 2) to
avoid assign self.