Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Give declarations of operator functions for each of the following ways to ove

ID: 3919311 • Letter: 1

Question

1) Give declarations of operator functions for each of the following ways to overload operator + you must state where the declaration goes, whether within the class in the public or private section or outside the class. The operator + may be overloaded

a) as member function

b) non-member function

2) Describe the syntax for a function template.

3) Describe polymorphism

4) Describe overloading, overriding and redefining

5) When a derived class inherits from a base class, how is the base class constructor called?

6) What are not inherited from base class

Explanation / Answer

template <class name>

name function_name(arguments){

}

Templates are created to accept the type which is not specified. Here template and class are keywords. name and function_name can be anything of your choice. Arguments are of type name.

For example - Template <class T>

T getSum(T a,T b){

return (a+b);

}

This funtion will be called as - getSum<int>(5,8);

3. Polymorphism

The word polymorphism means having many forms.It is the ability to behave differently in different situations. It is an important feature of Object oriented programming.

It is of two types - Compile time polymorphism and runtime polymorphism.

Compile Time Polymorphism can be achieved with function overloading and operator overloading. Whereas runtime polymorphism is achieved with function overriding.

4. Overloading, Overriding , Redefining

Overloading - A function with same name and different arguments are called function overloading.

Like - int Sum(int a, int b) - will take int arguments

void Sum(float a, int b) - will take both float and int arguments

Functions overloading is not based on different return types, it is based on different arguments

Overriding -  Overriding is when a function is already defined in a class and you inherit and make changes in same function, then that function is said to be overridden. The prototype of function remains the same in overriding.

Redefining- Redefing is done at compile time where reference variable type determines which method to use. while in overriding this is done at runtime based on the object type.

5. The base class default contructor is always called before derived class constructor whether you call a derived class default  contructor or parametrized constructor.

If you want to explicitly call base class parametrized contructor then you can write it as shown in below example;

Derived (int j) : Base (j) {

}

This will call base parametrized constructor.

6. The private data members and member functions are not inherited from base class.