给出矢量尺寸时出错

Error when giving a vector of vectors it's dimensions

本文关键字:出错      更新时间:2023-10-16
class tablero
{
int filas_; //initialize both ints
int columnas_;
vector < vector < casilla > > casilla_; // a vector of vectors of Casillas
public:
tablero(int filas, int columnas)
// The above is an initialization list
// We initialize casilla_ as a vector of filas vectors of columnas Casillas
{
  filas_=filas; //put the rows in the row int
 columnas_=columnas; // and the columns in the columns
 casilla_ = filas , vector<casilla>(columnas); // and set the dimensions of the vector of vectors.
}

它给了我"与'operator='不匹配"(操作数类型为'std::vector>'和'int')"错误在casilla_= filas,vector(columnas).filas(rows)columnas(columns)。

我认为一切都很好,但我真的不知道为什么会出现此错误。在 Tablero.h 中,我的构造函数是:

class Tablero {
public:
Tablero(int filas,int columnas); //I added both ints because I had an error in the main.
virtual ~Tablero();
void setcol(int n); //other methods
void setfilas(int n);
vector<vector<casilla> > getCasilla();
void setCasillac(int n ,int t, casilla c);
casilla getCasillac(int n ,int t);
};

如果你需要类卡西利亚和其他东西,只要说出来,我会发布它。我是 c++ 和 eclipse 的新手,我习惯了 Netbeans 和 Java,我不知道如何处理这些例外。

感谢任何可以帮助我的人,当然,如果你需要更多的代码,说出来,我会编辑这篇文章并放进去。

错误告诉您无法将 int 分配给向量:

用:cassilla_.储备(丝虫) ;向量(列) ;

或者使用指向这些的指针并在构造时传入值。