2015-05-29 36 views
2

我收到以下錯誤:在命名空間「STD」「陣列」沒有指定的模板類型

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

我改變編譯器來克++ 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) 
+5

你確定你用'-std = C++ 11'編譯? –

+0

請顯示您的編譯器行。 – merlin2011

+0

我不積極。我將如何確定?/我將如何改變這種情況?編輯已添加。 –

回答

7

剛讀什麼編譯器告訴你!

/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頭,因此,如果您修復第一錯誤,那麼後來者會消失。

閱讀編譯器錯誤。當開始在頂部和修復第一位的,不要只挑輸出固定的隨機部分。以後的錯誤往往是由較早的錯誤引起的,所以先修復先前的錯誤。

+0

你說得對。愚蠢的錯誤。現在很好。然而,我的IDE中的註釋並不反映這種變化。我正在使用eclipse。你知道如何做出改變。沒有什麼大不了的,只是很煩人。 –

+0

https://wiki.eclipse.org/CDT/User/NewIn83#Toolchains –

相關問題