Is there any way to use operator overloading in dynamic C++ object

I want to use operator overloading with dynamic object in C++

how can i do it?


I think by dynamic object you mean objects created to heap, so they are referenced as pointers. You are right, using overloaded operators for such objects is not as comfortable as local objects. But it is possible. And it looks terrible. And because we are talking about C++, there's more than one way to do it.

Let's say we have a class called Irrational, which overloads the += operator, you can do:

Irrational* a = new Irrational(2,-4);

Irrational* b = new Irrational(2,-4);
(*b) += 3;

So a heap object's overloaded operator is called either by calling it with the "operator" prefix, in which case it is a lot like a function call, or by converting the pointer first to a reference, in which case it works more "normally". That's it.

Need Your Help

How to convert MultipartFile into byte stream

java spring hibernate

//Or any other solution to saving multipartfile into DB.

Difference between a servlet and a proxy servlet

java javascript servlets proxy-server

What is the difference between a servlet and a proxy servlet (or in short what does proxy mean in this context)? How/Why routing backend calls though a proxy servlet, instead of http calls, in

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.