Cardona Jeison Cardona Jeison - 3 months ago 101
C++ Question

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

The failed is in the constructor of the class manejo.cpp, the error is "manejo.cpp:3:16: error: array used as initializer" and i don't know where this error.

to down is attached the source code of the class manejo.hpp and the implementation of manejo.cpp, thanks

#include "manejo.hpp"

manejo::manejo(){}
manejo::~manejo(){}


Hpp

#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

Answer

This

 char cadena[128]="";

is not legal in traditional C++ (it is legal in C++11 but clearly you're not using that because otherwise you wouldn't get this error). Delete ="", initialise data members in your constructor, not in your class. E.g.

manejo::manejo()
{
    cadena[0] = '\0';
    ...
}