2012-04-13 36 views
3
ため

をコードブロックを使用しながら、それがコンパイルされないと、コンパイラは私にこの奇妙なエラーが発生します。このコードGCCエラーのconst unsigned long型

class Reflect : public flemax::annotation::XAnnotation { 
    public: 
    Reflect(const unsigned long id, const std::string& home, const char type, const std::string& name = "me", const int value = 4, const bool valid = false, const signed char gender = 'M') : id_(id), home_(home), type_(type), name_(name), value_(value), valid_(valid), gender_(gender){} 
    ~Reflect() {} 

    const unsigned long id() { return id_; } 
    const std::string& home() { return home_; } 
    const char type() { return type_; } 
    const std::string& name() { return name_; } 
    const int value() { return value_; } 
    const bool valid() { return valid_; } 
    const signed char gender() { return gender_; } 

    private: 
    const unsigned long id_; 
    const std::string home_; 
    const char type_; 
    const std::string name_; 
    const int value_; 
    const bool valid_; 
    const signed char gender_; 

}; // class Reflect 

を考えてみましょう。

||=== flemax_base, DebugAnnotator ===| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|21|error: expected ‘,’ or ‘...’ before ‘long’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|24|error: expected ‘;’ before ‘long’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|25|error: expected ‘;’ before ‘const’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|33|error: expected ‘;’ before ‘long’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc||In constructor ‘flemax::test::Reflect::Reflect(int)’:| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|21|error: class ‘flemax::test::Reflect’ does not have any field named ‘id_’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|21|error: ‘id’ was not declared in this scope| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|21|error: argument of type ‘const int (flemax::test::Reflect::)()’ does not match ‘const int’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|21|error: argument of type ‘const bool (flemax::test::Reflect::)()’ does not match ‘const bool’| 
/programming/cpp-projects/flemax/flemax_base/base/xannottest.cc|21|error: argument of type ‘const signed char (flemax::test::Reflect::)()’ does not match ‘const signed char’| 
||=== Build finished: 12 errors, 0 warnings ===| 

符号なし修飾子を削除すると、すべて正常に機能します。 おそらく私は最後の24時間をコーディングしていますので、何が間違っているのか分かりません。 コードがコンパイルされるまで私は眠りたくありません。

は、Ubuntuのとgcc 4.4.3

上のコードブロックを使用していますおかげで、男性

答えて

3

あなたはどこかに#define unsigned WHATEVERがいると思います。あるいは、-Dunsigned=WHATEVERでコンパイルしているかもしれません。

したがって、コンパイラはどこでもconst WHATEVER long xと表示され、long型は意味を持ちません。

+0

このような考え方は、まったくバグではありませんでした。ありがとう!! – maress

+0

私が今思うのは、そのマクロが最初にどのように定義されたのかということです。 – rodrigo

+0

コードが生成されていたので、どのタイプのマクロが型に対して定義されているのかわかりませんでした。生成されたコードがコンパイルされているかどうかを調べるテストでした – maress

0

このコードは、GCC 4.6.3を使用して、自分のコンピュータ上でコンパイルします。解決策は、コンパイラのバージョンを最新のものに変更することです。

しかし、これは奇妙なエラーです。おそらく、コンパイラのバグがあります。コンパイラのバージョンを変更したくない場合は、クラスの先頭にプライベートセクションを置いてみてください。助けて欲しい。

+0

"コンパイラ"?確かにあなたは "コンパイラ"を意味します。 – DCoder

+0

申し訳ありませんが、これは正しい言葉です。 –

+0

プライベートセクションを最初に持つように変更するとgcc/g ++ 4.6.2に更新されません。 – maress

関連する問題