错误数组用作初始值设定项,我不知道错误

Error array used as initializer and i don't know the error

本文关键字:错误 我不知道 数组      更新时间:2023-10-16

失败是在类manejo的构造函数中.cpp,错误是"manejo.cpp:3:16:错误:数组用作初始值设定项",我不知道这个错误在哪里。

向下附上了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] = '';
    ...
}
相关文章: