Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Posted on 2013-06-12
Medium Priority
280 Views

http://www.cplusplus.com/doc/tutorial/classes2/

Please explain in some detail.  Does statement 'c = a + b' call  the operator+ function.  Please
step through the operator+ function.  Is it called twice?  Once with passing a, and another time passing b.  How does this functions add (3+1, 1+2) = (4,3).
0
Question by:naseeam
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 18

Accepted Solution

lludden earned 2000 total points
ID: 39241262
The + operator is the same as calling a method of the class, in this case operator+,
so c = a + b is the same as c = a.operator+ (b)

So, if we were adding vectors, you would have c = (3,1) + (1,2)  which is the same as (3,1).operator+(1,2)

The method already knows its own value, so we just pass into it the data that is being (in this case) added to it.
0

LVL 1

Author Closing Comment

ID: 39241343
Nice concise explanation!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
###### Suggested Courses
Course of the Month4 days, 21 hours left to enroll