此模板中的类型是什么
What is the type in this template?
std::tr1::_Bind<void (*()(std::tr1::reference_wrapper<int>))(int&)>
我理解std::tr1::reference_wrapper<int>
,整个事情是某种函数指针,它返回void
并将int&
作为参数。但是我似乎一开始就无法遵循*()。代码是从我不久前经历的一些 gdb 会话中剪切粘贴的。
另外,tr1::函数的类型是什么?某个返回 void 并且不带参数的函数?
0x00000001000021a1 in std::tr1::function<void ()()>::operator() (this=0x7fff5fbffb98) at functional_iterate.h:865
但是,以下是一个错误:
template <typename T>
void f()
{
cout << "generaln";
}
template<>
void f<void ()()> () // this is error
{
cout << "specificn";
}
这是一个实例,
std::tr1::_Bind
实例化在一个函数的类型上,该函数采用std::tr1::reference_wrapper<int>
并返回指向一个函数,该函数引用了对int的引用并返回void。
阅读方法如下:
-
std::tr1::_Bind<
类型>
应该清楚。 - type =
void (
fn)(int&)
是一个接受int&
并返回void
的函数。 - fn =
*
PTR,所以它实际上是指向函数的指针 - PTR =
(
fn2)(std::tr1::reference_wrapper<int>)
是一个std::tr1::reference_wrapper<int>
函数,到目前为止,我们拥有的是它的返回类型。 - fn2 =(空),因为我们没有给该函数(类型)一个名称。
但是,正如我现在注意到的那样,当 fn2 为空时,它周围的括号可能也不应该存在(类似于您将函数类型"函数不带参数并返回 void"写为 void()
,而不是void()()
。
std::tr1::function
的情况正是这样:一个不带参数并返回void
的函数,空的"函数名称"周围有额外的括号。
好的,现在测试了它:gdb确实输出void()
为void()()
;这可能应该被认为是gdb错误。
因此,在C++中编写第一种类型的正确方法是:
std::tr1::_Bind<void (*(std::tr1::reference_wrapper<int>))(int&)>
相关文章:
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- 如何声明一个标准::提升直方图的向量?提升直方图的类型是什么?
- 类名后跟括号的类型是什么
- std::chrono::duration::count函数的实际结果类型是什么
- c++运算符重载-我实际返回的操作数类型是什么
- 运算符和返回类型是什么意思?
- 指向 2D 数组的指针的类型是什么?
- RSA_verify中预期的数据类型是什么,无法验证从 Java 生成的签名
- 共享_ptr中多功能数组的类型是什么
- 构造函数的类型是什么?
- 字符串中单个字符作为数组的数据类型是什么
- 该结构继承的类型是什么
- 如果我获得Integer和Double的产品,输出的数据类型是什么
- C 中被视为可可的类型是什么
- 当函数采用右值引用时,函数中该变量的类型是什么?
- STD :: SETW,STD :: SETFILL等的真实返回类型是什么?
- 模板类中引用的引用的类型是什么
- const自动参考绑定到(NULL)指针 - 实际类型是什么
- 包含通过引用捕获的 lambda 函数的"variable"的类型是什么?
- 通过插座发送的内容的数据类型是什么