で「タプル」の宣言を禁止しますstd::
を忘れるか、またはヘッダーに<tuple>
を含めてください。しかし、私は両方を持っています。ここに私のコードです:ISO C++には、単純なクラス(<code>g++ myclass.cpp</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);
}
私は2番目のint
を除外し、<set>
を含めて、代わりにpair
を使用して同じことを行う場合、 できます。
私には何が欠けていますか?
編集:ここでは
がフル出力である:あなたが-std=c++11
(または、g++
-std=c++0x
の古いバージョンのための)を追加した場合
$ 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)
コードをコンパイルするときに '-std = C++ 11'を指定しましたか? –
'using namespace std;' - どのような冒涜です! –
このエラーは再現できません。このコードを正確に使用してもよろしいですか? g ++が報告した正確な行をマークする必要があります。 – Zeta