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

标签 c++

失败在类 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/

相关文章:

C++ 冒泡排序链表

C++ 获取对象

c++ - 在二维数组中查找最大的 2x2 平均值

c++ - 如何使用 boost::optional 传递可选输入参数

c++ - String 和 Bool(Int 条件为假)C++

c++ - 轻松的排序和线程间可见性

c++ - 使用 libcurl 和 C++ 将图片上传到受密码保护的目录

c++ - vector .push_back

c++ - 将带有非 ascii 数据的 std::string 写入文件

c++ - C++ 对指针容器进行排序并比较类型