8 Years
Discussion Span
Last Post by lotrsimp12345

Normally overload operators so that you can do mathematical or other operations with c++ classes. for example: cout << MyClass; assuming MyClass is an instance of some c++ class and you want that class to print the value of its class variables to the screen. Or you might want to add them MyClass++; There are lots of things you can do with overloaded operators, those are just two of them.

Which operators to overload depends on the c++ class and what you want it to do.


You overload an operator when it makes sense to do so.

Say that you create a custom string class MyString.

It makes sense to overload the + operator, but not the ~.


i have a project which i am working on. I am supposed to read in a phrase then every time it encounters a space the word is supposed to go to a newline in my output. The phrase can take up only one line. The phrase can be read from a file or from cin. The phrase contains spaces so i am guessing you are supposed to overload input >> to make it take a space containing line when they enter cin>>string word. by overloading with getline()???

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.