Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Beginner
Sep 28, 2004



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Simplify Operator Overloading

For beginning C++ programmers, operator overloading may seem like a complicated task, but in fact, it's really simple. You can overload operators in two ways:
  • On non-member functions.
  • On member functions.
When overloading operators on non-member functions, the expression looks like @ is the operator and a and b are two separate objects that are pass into operator @(a,b).

This example isn't necessarily useful, but it helps to explain overloading operators on non-member functions.

int operator+(int a, int b)
   return (a + b);
When overloading operators on member functions, the expression looks like a is some other object. The function should look like this: operator @(a). Simple right? Here's what it looks like:

void class::operator++()

Sophy Pal
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date