函数指针是C ++中的函数对象吗? [英] Are function pointers function objects in C++?
问题描述
C ++标准将函数对象定义为:
The C++ standard defines function objects as:
函数对象类型是一种对象类型,可以是$ b的类型在函数调用中$ b postfix-expression。 (链接)
A function object type is an object type that can be the type of the postfix-expression in a function call. (link)
首先,我想到函数对象是函子,但后来我意识到对于函数指针 ptr
类型 P
(不是函数,而是函数指针), std :: is_object_v< P>
是 true
,可以使用 ptr(Args ...)
语法来调用。
First I was thinking that function objects were functors, but then I realized that for a function pointer ptr
of type P
(not a function, but a function pointer), std::is_object_v<P>
is true
and can be called with the ptr(Args...)
syntax.
我正确的说,函数指针被标准视为函数对象吗?如果它们不是定义的哪一部分不被函数指针所满足,那么它们就是这样。
I am right that function pointers are considered as function objects by the standard? And if they are not what part of the definition is not satisfied by function pointers?
推荐答案
C ++标准中的术语对象在OOP意义上并不意味着对象。一个 int
是一个对象。
Yes, they are. The term "object" in C++ standard does not mean "object" in the OOP sense. An int
is an object.
这篇关于函数指针是C ++中的函数对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!