Overloading + operator

Overloading + operator

Question:
I’ve been working on the + operator in my string class. I came across an interesting dilemma: the following code doesn’t call any of my + operators.For example:

String st1;st1 = "Hello" + "world";

Do I need a special kind of function to handle the type of format? I can get this to work:

String st1("Hello");st1 = st1 + "world";

Answer:
There’s really nothing you can do about this. The problem is that you are adding two char pointers together, which have nothing to do with your class. Only after these are somehow added would your class come into play. It’s exactly the same situation with the string class that comes with Microsoft’s MFC.

The only way to handle this is to change the way the class is used. If you add only one string at a time, it can be done.

st1 = “Hello “;st1 += “world”;
Here, each word is added directly to your class and allows your class to control how.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes