小编I-m*_*man的帖子

奇怪的错误,设置<int> :: begin()总是返回const迭代器

为什么set.begin()总是返回一个const迭代器而不是一个标准迭代器呢?

35 int test(){
36     std::set<int> myset;
37     myset.insert(2);
38     myset.insert(3);
39     int &res = *myset.begin();
40     return res;
41 }


test.cpp:39: error: invalid initialization of reference of type ‘int&’ from expression of type ‘const int’
Run Code Online (Sandbox Code Playgroud)

c++ const g++ set

5
推荐指数
1
解决办法
1303
查看次数

标签 统计

c++ ×1

const ×1

g++ ×1

set ×1