失败在类 manejo.cpp 的构造函数中,错误是“manejo.cpp:3:16: error: array used as initializer”,我不知道这个错误在哪里。
下面附上manejo.hpp类的源码和manejo.cpp的实现,谢谢
#include "manejo.hpp"
manejo::manejo(){}
manejo::~manejo(){}
惠普
#ifndef __MANEJO_HPP
#define _MANEJO_HPP
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
using std::vector;
using std::string;
class manejo{
private:
char cadena[128]="";
vector <string> linea;
long cantidadPD = 0;
vector <string> palabras;
int Creglas = 0;
vector <string> reglas;
long atoi(const char *str);
public:
manejo();
~manejo();
void EstablecerVariables();
int StoInt (string numero);
};
#endif
最佳答案
这个
char cadena[128]="";
在传统 C++ 中是不合法的(在 C++11 中是合法的,但显然你没有使用它,否则你不会得到这个错误)。删除 =""
,在您的构造函数中初始化数据成员,而不是在您的类中。例如
manejo::manejo()
{
cadena[0] = '\0';
...
}
关于c++ - 用作初始值设定项的错误数组,我不知道错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19347049/