c++ - read-only variable is not assignable问题
本文介绍了c++ - read-only variable is not assignable问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
不知道该如何叙述这个问题,请看代码:
#include <set>
#include <iostream>
using namespace std;
struct test {
int data[3];
};
int main(void) {
test t1;
set<test> s;
s.insert(t1);
s.begin()->data[0] = 1;//此处赋值报错:read-only variable is not assignable
return 0;
}
应该是set内部的问题吧?
求高人解释,非常感谢...
解决方案
set内的元素不可以更改,只能增加或者删除。http://www.cplusplus.com/refe...
Sets are containers that store unique elements following a specific order.
In a set, the value of an element also identifies it (the value is itself the key, of type T), and each value must be unique. The value of the elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.
Internally, the elements in a set are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).
set containers are generally slower than unordered_set containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order.
Sets are typically implemented as binary search trees.
这篇关于c++ - read-only variable is not assignable问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文