()运算符在C ++中做了什么 [英] What does the () operator do in C++

查看:84
本文介绍了()运算符在C ++中做了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读我的C ++书籍,它提供了关于()运算符的非常少的信息 - 他说这不是很重要,但我很想知道这个算子是什么,也许我会在某一天使用它。



谢谢,Sam

Hi, I was reading my C++ book which a gave a very little information about the () operator - He said that's not very important, But I'm curious to know what is this operator, maybe I'll use it someday.

Thanks, Sam

推荐答案

您可以将()运算符视为没有类的方法一个名字,因为它(几乎)是你调用这个运算符时的样子:而不是

You can think of the () operator as a classs method without a name, because that is (almost) how it looks when you invoke this operator: rather than
myobject.foo();
myobject.bar(1, 3.13, "hello world");



来电看起来像这样:


the calls would look like this:

myobject();
myobject(1, 3.13, "hello world");



请注意,'。'缺失;这是有目的的,因为这个想法是像类函数一样使用类对象。这个操作符的主要用途是函数编程(记住,C ++不是面向对象的语言,它是一种通用语言,因此适用于任何编程范例!),以及通用编程。


Note that the '.' is missing; this is on purpose, because the idea is to use the class object like a function. The main use of this operator is in functional programming (remember, C++ is not an object oriented language, it is a general purpose language, and therefore suitable for any programming paradigm!), and in generic programming.

这就到了这一点。

https://en.wikipedia.org/wiki/ Function_object [ ^ ]
This gets to the point.
https://en.wikipedia.org/wiki/Function_object[^]

这是函数形式函数调用运算符或转换(C样式转换)运算符。我不知道一本书怎么能用7行来解释它,我没有热情去发现。使用体面的东西:

https://en.wikipedia.org/wiki/Operators_in_C_and_C% 2B%2B [ ^ ],

http://www.cplusplus.com/doc/tutorial/operators [ ^ ],

http://www.tutorialspoint.com/cplusplus/function_call_operator_overloading.htm [ ^ ],

http://www.cplusplus.com/doc/tutorial/typecasting [ ^ ],

https://msdn.microsoft.com/en-us/library/df74sak1.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/ts48df3y.aspx [ ^ ]。



-SA
This is a functional form or function-call operator or conversion (C-style cast) operator. I have no idea how a book can explain it all in 7 lines, and I have no enthusiasm to find out. Use something decent:
https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B[^],
http://www.cplusplus.com/doc/tutorial/operators[^],
http://www.tutorialspoint.com/cplusplus/function_call_operator_overloading.htm[^],
http://www.cplusplus.com/doc/tutorial/typecasting[^],
https://msdn.microsoft.com/en-us/library/df74sak1.aspx[^],
https://msdn.microsoft.com/en-us/library/ts48df3y.aspx[^].

—SA


这篇关于()运算符在C ++中做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆