Skip to main content

Posts

Showing posts with the label types operators which cannot be overloaded

List different types operators which cannot be overloaded? Write a program to read two strings and concatenate them showing the example of operator overloading.

 Operators that cannot be overloaded in C++ are: The scope resolution operator (::) The member selector operator (. or .*) The ternary operator (?:) The sizeof operator The typeid operator The comma operator (,) Here's an example program that demonstrates operator overloading to concatenate two strings: #include <iostream> #include <cstring> using namespace std; class String {   private:     char* str;   public:     String() {         str = new char[1];         *str = '\0';     }     String(const char* s) {         str = new char[strlen(s) + 1];         strcpy(str, s);     }     ~String() {         delete[] str;     }     String operator+ (const String& s) {         String result;         delete[] result.str;         res...