【问题标题】:CodeBlocks error with Strings and Structures字符串和结构的 CodeBlocks 错误
【发布时间】:2015-03-29 12:30:08
【问题描述】:

这是我在 Codeblocks 上制作的 C++ 头文件。在编译时,IDE 给我一个错误提示:'FailureToFindScriptFileError' does not name a type 我已经在互联网上交叉检查了有关应该如何实施结构的资源,但我似乎找不到问题所在。此外,当我在主文件中输入相同的代码时,它运行没有任何问题。谁能指出我在这里做错了什么?

#ifndef SCRIPT_H_INCLUDED
#define SCRIPT_H_INCLUDED

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;
struct ErrorId
{
    char* numberID;
    char* quote;
};

ErrorId FailureToFindScriptFileError;

FailureToFindScriptFileError.numberID = "0001";
FailureToFindScriptFileError.quote = "Script File could not be found.";

#endif

【问题讨论】:

    标签: c++ compiler-errors ide structure codeblocks


    【解决方案1】:

    问题是您在函数之外有两个指令(即两个分配)。您必须在声明结构时对其进行初始化:

    ErrorId FailureToFindScriptFileError = { "0001", "Script File could not be found." };
    

    例如,另一个选项是将分配移动到main 函数中。

    【讨论】:

      猜你喜欢
      • 2014-04-28
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      相关资源
      最近更新 更多