Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISO C++ forbids declaration of ‘tuple’ with no type

When trying to compile a simple class (g++ myclass.cpp), I get the following error:

ISO C++ forbids declaration of ‘tuple’ with no type

I searched for this problem, and in most cases people seemed to forget std:: or including <tuple> in the header. But I have both. Here is my code:

myclass.h

#ifndef MYCLASS
#define MYCLASS

#include <iostream>
#include <tuple>

class MyClass {
    std::tuple<bool, int, int> my_method();
};

#endif

myclass.cpp

#include "myclass.h"

using namespace std;

tuple<bool, int, int> MyClass::my_method() {
    return make_tuple(true, 1, 1);
}

If I do the same using pair instead, leaving out the second int and including <set>, it works.

What am I missing?

EDIT:

Here is the full output:

$ g++ myclass.cpp -o prog
In file included from myclass.cpp:1:
myclass.h:7: error: ISO C++ forbids declaration of ‘tuple’ with no type
myclass.h:7: error: invalid use of ‘::’
myclass.h:7: error: expected ‘;’ before ‘<’ token
myclass.cpp:5: error: expected constructor, destructor, or type conversion before ‘<’ token

$ g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658)
(LLVM build 2336.11.00)

like image 374
Jawap Avatar asked Dec 22 '12 19:12

Jawap


1 Answers

GCC 4.2.1 shipped with every mac is outdated. It will not recognize the C++11.

You need to compile your code using: c++ instead of g++ which calls clang, which is the officially updated compiler on mac.

c++ -std=c++11 -stdlib=libc++ myclass.cpp -o prog 

You are required to link against libc++ which is clang lib which knows about c++11 features instead of the default libstdc++ used by gcc.

like image 123
Kirell Avatar answered Sep 19 '22 14:09

Kirell