declaring set of sets with integer in c++

最后都变了- 提交于 2019-12-23 06:12:52

问题


I am working on a c++ program with a set of sets. Here is the declared set of sets.

std::set< std::set<int> > temp_moves;

I am getting the error below in this declaration, my question is that is my syntax correct? is it possible to create a set of sets in programs?

error: no matching function for call to ‘std::set<std::set<int> >::insert(int&)’

Updated Code

   std::set<int> next_moves;
   std::set<int> available_numbers;
   for (const auto available_number : available_numbers)
        temp_moves.insert(number);
        temp_moves.insert(available_number);
   next_moves.insert(temp_moves);

回答1:


You are inserting an integral value available_number into a data structure temp_moves that expects a set...

Probably not the logic that you want to achieve, but the following will at least compile. Hope it helps somehow:

std::set<int> next_moves;
std::set<int> available_numbers;
for (const auto available_number : available_numbers) {
  next_moves.insert(available_number);
}
temp_moves.insert(next_moves);


来源:https://stackoverflow.com/questions/47253499/declaring-set-of-sets-with-integer-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!