Exploring C++ Friend Functions

Exploring C++ Friend Functions

What is a Friend? A friend declaration appears within a class and grants a function or another class access to the private and protected members of the class that declares the friend (https://en.cppreference.com/w/cpp/language/friend.html). Points to note: Friend declarations are made within the class, but their specific location is not restricted and is not subject to … Read more

Lesson 18: Friend Functions and Friend Classes in C++

Lesson 18: Friend Functions and Friend Classes in C++

The Concept of Friend In C++, an important feature of classes is encapsulation, which protects and hides the internal data of a class by categorizing data members and member functions into three access levels: private, protected, and public. Private members can only be accessed by the member functions of the class itself, and external functions … Read more

C++ Learning Manual – Operator Overloading and Friends – Operator Overloading (+, -, <<, >>)

C++ Learning Manual - Operator Overloading and Friends - Operator Overloading (+, -, <>)

Why Overload Operators? Imagine you have created a class <span>Complex</span> that represents complex numbers, containing real and imaginary parts. You want to use operations like <span>c1 + c2</span> directly, just like with basic types, instead of calling a function like <span>c1.add(c2)</span>. This is the purpose of operator overloading – to make custom types as convenient … Read more