我找到了这样的代码:
template <typename T, typename T1> auto compose(T a, T1 b) -> decltype(a + b) {
return a+b;
}
Run Code Online (Sandbox Code Playgroud)
我想到了所有细节,这对我来说是新的,但只有一个.请告诉我,在哪里可以阅读,箭头操作符(->
)在函数标题中的含义是什么?我纯粹从逻辑上说,那个->
算子确定了一个类型,auto
但是我希望得到这个,但找不到信息.
所以我目前正在攻读有关数据结构和算法开发的C++考试.虽然看着我的老师powerpoint,但我注意到他经常使用这个" - >".我不确定这意味着什么?它真的是一个你可以用c ++做的命令吗?
例1
addrInfo *ptr = head;
while (ptr->next != NULL)
{
ptr = ptr->next;
}
// at this point, ptr points to the last item
Run Code Online (Sandbox Code Playgroud)
例2
if( head == NULL )
{
head = block;
block->next = NULL;
}
Run Code Online (Sandbox Code Playgroud) 请注意,这不是C++中的含义 - >意味着什么?
这个问题特定于C++ 11; 函数可以是这样的:
struct string_accumulator {
}
inline auto collect() -> string_accumulator
{
return string_accumulator();
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下, - >的含义是什么?