小编Rha*_*eem的帖子

为什么在嵌套函数中调用 std::begin 时行为不同

我有一些简单的代码

#include<iterator>

int main() {
    int y[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    auto a = std::begin(y);
    std::cout << *a << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

1按预期打印出来。

但是如果我这样做:

void checkNested(int val [10]) {
    auto a = std::begin(val);
    std::cout << *a << std::endl;

}

int main() {
    int y[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    checkNested(y);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

clang++我从和得到编译失败g++。具体来说clang++我得到:


    auto a = std::begin(input);
             ^~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/initializer_list:89:5: …
Run Code Online (Sandbox Code Playgroud)

c++ linux iterator compiler-errors clang++

0
推荐指数
1
解决办法
56
查看次数

标签 统计

c++ ×1

clang++ ×1

compiler-errors ×1

iterator ×1

linux ×1