The Visual C++ Programming Tutorials: C++ Operator & Function Overloading
| |
|
C++ You’ve already seen how to construct classes and structs, provide member functions in your types, and use these functions in programs. In this module, you’re going to find out about a special category of member functions called overloaded functions (and overloaded operators), which allow you to add extra functionality so that your types can be used more naturally and intuitively. If you’ve met operator overloading in C++ before, you need to be aware that overloading is handled completely differently in managed C++ than in traditional C++ though the syntax-wise may be similar. In fact, managed C++ types aren’t allowed to implement traditional C++ overloaded operators, so you’ll need to pay close attention to this module to find out how operator overloading is now done. You already met the operators provided by the C++ language before. The problem is that those operators work only with the built-in types, and you’re starting to use classes and structs to define your own data types. This means that if you want to do an addition operation or a comparison operation on types that you’ve created, you can’t use the + and == operators because the compiler doesn’t know how to apply them to your types. Operator overloading is a C++ feature that lets you define operators to work with your types, that is a user defined type which can often lead to a more natural style of programming. Generally, overloaded operators are needed by classes that wrap simple values.
|
Best viewed using FireFox, Chrome etc. Worst viewed using IE of any version
Webmaster contact: [contact[@]visualcplusdotnet.com] Copyright 2019 © Visualcplusdotnet. All rights reserved. Excellent hosting services provided by MochaHost - The Online Central
| About | Disclaimer | Privacy | Site Index & Project Download | Native C | Contact | | |
Custom Search | |
|
|