declaring set of sets with integer in c++

2019-06-14 18:32发布

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);

标签: c++ set
1条回答
迷人小祖宗
2楼-- · 2019-06-14 19:06

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);
查看更多
登录 后发表回答