【发布时间】:2015-04-16 15:41:20
【问题描述】:
当我尝试将数字保存到我的向量中时出现此错误...
Invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
代码是:
class Elemento{
private:
int Nodo;
public:
Elemento(){};
~Elemento(){};
void SetNumero(int x) { Nodo = x; };
int GetNumero() { return Nodo; };
};
class MagicSquare{
private:
int N;
int Possibili_N;
int Magic_Constant;
vector<Elemento> Square(int Possibili_N);
public:
MagicSquare() { };
~MagicSquare() { };
void Set_N(int x) { N = x; };
void Set_PossibiliN(int x) { Possibili_N = x; };
void Set_MagicConstant(int x) { Magic_Constant = x; };
. . .
void SetSquare(int i, int x) { Square[i].SetNumero(x); }; // got error here
int GetSquare(int i) { return Square[i].GetNumero(); }; // got error here
};
每当我使用 Square[i].method() 时都会出错...
我调用了一个方法来传递 Square 中的索引和要放入 Elemento->Nodo 的值,但我必须使用公共方法来访问私有 Nodo。与 GET 相同。我想获取显示它的值。
【问题讨论】: