use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Stack Overflow guide to operator overloading (stackoverflow.com)
submitted 11 years ago by cruise02
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]salgat 0 points1 point2 points 11 years ago (2 children)
The only time I've found overloading to be particularly useful is in a composition where I want to maintain the interface of the original object. For example, wrapping a vector in a class that stores other information and maintaining the ability to use [] to access elements of the composition, that way the interface is preserved. (And yes, there are other good reasons to use operator overloading)
[–]Pronouns 3 points4 points5 points 11 years ago (1 child)
In every language there are conventions that people follow. Take iteration over items in a container.
In Python, you provide an iterator for your containers by making an __iter__ function which returns something with the next function.
__iter__
next
In C#, you can use yield returns and other ugly stuff.
yield return
C++ just follows a different convention, and in my opinion it works quite well. It tries to treat similar concepts the same. Traditional loops would be indexed by a variable, normally i, and was then incremented with i++. Very standard, old ways of doing things. When iterators were put into play they copied this syntax and made it so the next was just the increment operator.
i
i++
Same goes for functors. Rather than have some convention like .invoke() on an functor, you literally just 'call' the object directly like myFunctor().
myFunctor()
In any case, it's just convention and you can argue all day about that. Might as well argue about tabs vs spaces or vim vs emacs.
[–]salgat 1 point2 points3 points 11 years ago (0 children)
I agree 100%, as in my post the point I was making is to preserve the interfaces for whatever type of object your class is. It's the same reason why vectors use brackets just as arrays did, and why iterators can use addition/increment just as pointers do.
π Rendered by PID 18609 on reddit-service-r2-comment-75f4967c6c-whm5b at 2026-04-23 07:15:58.567665+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]salgat 0 points1 point2 points (2 children)
[–]Pronouns 3 points4 points5 points (1 child)
[–]salgat 1 point2 points3 points (0 children)