【发布时间】:2016-05-26 15:01:35
【问题描述】:
保存.cpp
#include "save.h"
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
Save::Save()
{
}
我已经注释了所有函数并从 Save::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
我使用 g++ 4.9 并在 C++11 中编译,它在 save.cpp 的第 6 行给出了这个错误,尽管我已经检查过了,但我是 c++ 新手,不太确定,这是根本不是初始化器。
这似乎是由我希望整个类都可以使用的常量成员的非静态数据成员初始化引起的编译器错误。
【问题讨论】:
-
请向我们展示您的头文件。
-
我也认为这应该编译,我很困惑为什么它没有
-
您实际上不需要指定
const char数组的大小。一旦你给它们赋值(就像你做的那样),编译器会自动计算它。 -
无关,但需要
#include <string>。 -
您使用的是
const string&,因此您需要正确的包含。无论如何,要解决您的问题,请在 C++11 模式下编译。
标签: c++ error-handling g++ g++4.9