c++ - 命名空间 'std' 中的“数组”未命名模板类型

标签 c++ arrays c++11 std

我收到以下错误:

'array' in namespace 'std' does not name a template type.

我将编译器更改为 g++ 4.9。仍然有问题。我想我可能有一个旧版本的 std 库,但不确定如何继续修复它。

#ifndef DBINTERFACE_H_
#define DBINTERFACE_H_

#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include "mysql_driver.h"
#include <array>

class DBInterface {
private:
    double Found_Buffer[100][59];
    int Found_Count;
    double New_Buffer[100][59];
    std::array<double, 5> BLAH;

    int New_Count;
    double M[59];
    double B[59];
    sql::mysql::MySQL_Driver *driver;
    sql::Connection *con;

public:
    DBInterface();
    virtual ~DBInterface();
    void Update();
    void Search();
    void Add2DB();
    void Add2Buffer(double Found_Objects[][59], double New_Objects[][59]);
    void Build();

    /*
     * To be added:
     * void CollapseBuffer();
     * void DetDynamic();
     *
     */
};

#endif /* DBINTERFACE_H_ */

错误信息:

17:20:06 **** Incremental Build of configuration Debug for project CANS ****
make all 
Building file: ../src/DBInterface.cpp
Invoking: Cross G++ Compiler
g++ -I/home/derek/soci/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/DBInterface.d" -MT"src/DBInterface.d" -o "src/DBInterface.o" "../src/DBInterface.cpp"
In file included from /usr/include/c++/4.9/array:35:0,
                 from ../src/DBInterface.h:17,
                 from ../src/DBInterface.cpp:8:
/usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
In file included from ../src/DBInterface.cpp:8:0:
../src/DBInterface.h:24:7: error: ‘array’ in namespace ‘std’ does not name a template type
  std::array<double, 5> BLAH;
       ^
../src/DBInterface.cpp: In function ‘void Add2Buffer(double (*)[59], double (*)[59])’:
../src/DBInterface.cpp:44:6: warning: unused variable ‘NoOfFO’ [-Wunused-variable]
  int NoOfFO;
      ^
../src/DBInterface.cpp:45:6: warning: unused variable ‘NoOfNO’ [-Wunused-variable]
  int NoOfNO;
      ^
make: *** [src/DBInterface.o] Error 1

17:20:08 Build Finished (took 2s.464ms)

最佳答案

只需阅读编译器告诉您的内容即可!

/usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

这告诉您您已经包含了一个 C++11 头文件(在本例中为 <array>),但您没有在 C++11 模式下编译。

它甚至会告诉您如何解决问题(使用 -std=c++11-std=gnu++11 )。

后面的错误说array没有命名类型是因为你在没有启用 C++11 的情况下包含了 C++11 头文件,所以如果你修复了第一个错误,那么后面的错误就会消失。

当阅读编译器错误时,从顶部开始修复第一个错误,不要只是随机选择输出的一部分来修复。后面的错误往往是由前面的错误引起的,所以先修复前面的错误。

关于c++ - 命名空间 'std' 中的“数组”未命名模板类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30540026/

相关文章:

c++ Hangman 游戏项目帮助如何在字符串中查找字母

javascript - 将项目添加到数组中 - 单独

c++ - 如何使用 std::copy_n 打印出 std::vector 的内容?

c++ - 对一个类中的一个 vector 进行排序,第二个 vector 应与第一个 vector 一起移动

c++ - unordered_map - 未定义模板的隐式实例化

javascript - 使用 JavaScript/jQuery 检查嵌套数组的获胜组合

c++ - 对于双映射

c++ - 为包含 union 的结构定义 `swap` 方法;怎么做?

c++ - 如何从 GLUT 坐标转换为窗口坐标

JavaScript 数组/结构体