Source |
CodingSec |
Identifiant |
359911 |
Date de publication |
2017-04-27 13:55:08 (vue: 2017-04-27 13:55:08) |
Titre |
How do you overload binary operators in C++ |
Texte |
As unary operators can be overloaded, we can also overload binary operators. Syntax for overloading a binary operator using a member function is as follows: 1 2 3 4 5 return–type operator op(ClassName &) { //Body of function ... } Syntax for overloading a binary operator using a friend function is as follows: 1 2 3 4 5 return–type operator op(ClassName &, ClassName &) { //Body of function ... } Following program demonstrates overloading the binary operator + using a member function: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
Envoyé |
Oui |
Condensat |
//body also appeared binary c++ can classname coding demonstrates first following follows: friend function function: how member operator operators overload overloaded overloading post program return–type security syntax unary using |
Tags |
|
Stories |
|
Notes |
|
Move |
|