How to fix this array used as initializer error?

M. Brückmann

save.cpp

#include "save.h"
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
Save::Save()
{
}

I've commented all the functions and removed the contend out from Save::Save but it doesn't affect the error.
save.h

#ifndef SAVE_H
#define SAVE_H
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
class Save
{
    public:
        Save();
        void vDisplay();
        char cDecode();
        bool bFileExists(const string& crsFileName);
        const char ccTab = 9;
        const char ccHelp[5] = "help";
        const char ccNo[3] = "no";
        const char ccStart[6] = "start";
        const char ccQuit[5] = "quit";
        const char ccYes[4] = "yes";
};
#endif // SAVE_H

I use g++ 4.9 and compile in C++11 and it gives me this error on the 6th line of save.cpp, altough, I've checked it but I'm new to c++ and not quite sure, this isn't an initializer at all.
It seems to be an compiler bug caused by the non-static data member initialization of constant members I want to be available to the whole class.

eerorika

The error message is confusing. It points to the constructor (which indeed doesn't even have an initializer list), even though the real culprit is this line (and the similar lines following it):

const char ccHelp[5] = "help";

GCC manual says that the feature is supported since 4.7, but 4.9 apparently fails to compiler your program. That appears to be a compiler bug. Remember that C++11 support was experimental until GCC 5.1. Here is your program reproducing the compiler bug in 4.9 and here is your program compiling fine in 5.1.

So, your options are 1) upgrade your compiler or 2) use uglier form of the initialization, which appears to work in 4.9:

const char ccHelp[5] = {'h','e','l','p','\0'}; // ugly :(

As a sidenote: You use std::string, but you forgot to include <string> where std::string is defined.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

boost::any library doesn't compile: "Array used as initializer" error

How do I solve the "array initializer must be an initializer list" error?

How to fix "Property has no initializer and is not definitely assigned in the constructor" error?

how to fix "Cannot invoke initializer for type 'MBMovingGround?' with no arguments" error in swift

How do I fix this child class' initializer list error?

how I fix this Error The instance 'widget' can't be accessed in an initializer

how to fix error: not a statement with += on an array

illegal initializer for char — how to fix?

Array initializer must be an initializer list error not shown

NumPy package gives an array() error how to fix this?

How to fix error: Array type required in Delphi

How to fix ESLint error Use array destructuring

How to fix MongoDB array concatination error?

How to fix a error with array in bash script?

how to fix "Index was outside the bounds of the array" Error

how to fix a Runtime error in a char array

How to fix Javascript associative array error

Getting an array iteration error, wondering how to fix it

How to fix 'declared but not used' compiler error in this simple program?

How to fix conversion error in a constructor in one of my used arduino libraries

How to fix Error: Non-nullable variable to be used?

Flutter: How to Fix a 'Multiple Widgets Used the Same GlobalKey' Error

How to fix database error in which exists function is used?

How to fix the error in left-recursion used with semantic predicates?

How to fix error used by new Place SDK for android

How to fix a nullable expression can't be used as a condition error

How to fix Error: useHref() may be used only in the context of a <Router> component

How to fix “Cannot invoke initializer for type 'MKMapRect' with an argument list of type '(MKMapRect)''” error in Swift 5.0