在 C++ 中用整数声明一组集合 [英] declaring set of sets with integer in c++

查看:36
本文介绍了在 C++ 中用整数声明一组集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有一组集合的 C++ 程序.这是声明的集合集合.

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&)’

更新代码

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

推荐答案

您正在将整数值 available_number 插入到数据结构 temp_moves 中,该数据结构需要一个集合...

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

这篇关于在 C++ 中用整数声明一组集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆