Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C++ function types and overloaded functions

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to use C++ function types and overloaded functions". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. First of all, for the overloaded function, it is clear that the return type of the function can not determine the category of the overloaded function, that is, int F (int, int); / / A function that returns int type void F (int, int); / / A function with no return value has the same formal parameter list and different return value types, but the two do not constitute overloaded function 2. Note the default values in the formal parameter list, which may be ambiguous when using overloaded functions with default parameters. For example: int a = 0 politics int Max (int,int); int Max (int,int,int = 0); / / the call to Max (3 Magi 5) will report an error a = Max (3 Magi 5); / / error

In addition, the default parameters should be specified when the function name is first given, usually in the function prototype. If the default parameters have been specified in the function prototype, the function definition cannot be repeated.

Question:

I saw such a problem in a question, which, in a nutshell, allows you to call an overloaded function passed by a value and an overloaded function passed by a reference.

# includeusing namespace std;void F (int & a, int & b) {a = a + b; cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report