الشرح التفصيلي لجميع شرائح المحاضرة (Slide-by-Slide) مدعوم بشرح الأكواد سطراً بسطر (Line-by-Line Code Explanation)
1. Which of the following C++ operators CANNOT be overloaded under any circumstances?
2. When overloading a Binary Operator (like `+`) as a standard member function of a class, how many parameters should the function take?
1. What is the main purpose of using Templates in C++?
2. Which of the following is the correct syntax to instantiate an object of a Class Template named `Stack` to hold integers?
+) عشان يشتغل مع الـ Objects. الـ Syntax: returnType operator OP (params).this). Binary Overloading: بتاخد Parameter واحد (الطرف اليمين).. و :: و ?: و sizeof ← مستحيل نعملهم Overloading.T والكومبايلر بيعمل نسخة لكل نوع بيانات تستخدمه.template <typename T> T func(T x) { }. Class Template: نفس الفكرة بس على كلاس كامل ولازم تحدد النوع وإنت بتعمل Object: Box<int> b;.Question: Explain Function Overloading and Operator Overloading as forms of Compile-Time Polymorphism. List the operators that cannot be overloaded. Then explain Templates (Function and Class) and how they achieve Generic Programming.
Q1:
Q2:
Q1: Write the signature of an overloaded + operator as a member function of class Complex that adds two Complex objects.
Q2: Write the signature of an overloaded prefix ++ operator as a member function of class Counter.
Q3: Write the signature of a generic Function Template called findMax that returns the larger of two values of type T.
a) What is the output?
b) In the expression p1 + p2, which object is implicitly passed and which is explicitly passed as a parameter?
c) Can we overload the sizeof operator in C++?