unique_ptr is a smart pointer available in C++ 11. Weak pointer is used along with shared pointers. You cannot create a standalone unique pointers. Example of weak pointer: #include <iostream> #include <memory> //for more C++ tutorial visit www.ProDeveloperTutorial.com using namespace std; class MyClass { public: MyClass() …
In this tutorial we shall see how to overload assignment operator “=”. #include <iostream> // for more tutorials check www.prodevelopertutorial.com using namespace std; class MyClass { private: int num_1; int num_2; public: MyClass(int a, int b): num_1(a), num_2(b){ } void operator = (const MyClass &obj …
In this chapter we shall see how to overload relational operators . #include <iostream> // for more tutorials check www.prodevelopertutorial.com using namespace std; class MyClass { private: int num_1; public: MyClass(int a): num_1(a){ } friend void operator < (MyClass &obj1, MyClass &obj2); friend void operator > …
In this chapter we shall see how to overload binary operators . Example: #include <iostream> // for more tutorials check www.prodevelopertutorial.com using namespace std; class MyClass { private: int num_1; int num_2; public: MyClass(int a, int b): num_1(a), num_2(b){ } friend MyClass operator + (MyClass &obj1, …
In this chapter we shall see: 1. Overloading prefix increment operator without return type 2. Overloading prefix increment operator with return type 3. Overloading Postfix increment operator 4. Overloading prefix and postfix decrement operator 1. Overloading prefix increment operator without return type Consider the example below; …