6

I receive the following error:

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

I changed my compiler to g++ 4.9. Still having issues. I think that I may have an old version of the std library but am not sure on how to proceed to fix that.

#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_ */

Error messages:

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)
4
  • 6
    And you're sure your'e compiling with -std=c++11? Commented May 29, 2015 at 22:30
  • Please show your compiler line. Commented May 29, 2015 at 22:34
  • I am not positive. How would I be sure?/ how would I change that? Edit Added. Commented May 29, 2015 at 23:27
  • 3
    I guarantee you you are not compiling in C++11 mode, that's what the "#error This file requires compiler and library support for the ISO C++ 2011 standard." error means. Look at the first error, because the later errors are caused by that. The first error tells you why you get the "'array' in namespace 'std' does not name a type" error, and even tells you how to fix it! But you've ignored it, why? Commented May 29, 2015 at 23:32

1 Answer 1

16

Just read what the compiler is telling you!

/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.

That tells you that you have included a C++11 header (in this case <array>) but you are not compiling in C++11 mode.

It even tells you how to fix the problem (use -std=c++11 or -std=gnu++11).

The later error saying array doesn't name a type is because you've included a C++11 header without enabling C++11, so if you fix the first error then the later ones will go away.

When reading compiler errors start at the top and fix the first one, don't just pick a random part of the output to fix. Later errors are often caused by the earlier ones, so fix the earlier ones first.

Sign up to request clarification or add additional context in comments.

1 Comment

You're right. Stupid mistake. It's fine now. My annotations in my IDE doesn't reflect the change however. I'm using eclipse. Do you know how to make the change. Not a huge deal, just annoying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.