3

このコードを検討してください

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 でコードブロックを使用しています

ありがとう男性

4

2 に答える 2

3

私はあなたが#define unsigned WHATEVERどこかに持っているに違いない. または、 でコンパイルしている可能性があります-Dunsigned=WHATEVER

そのため、コンパイラはconst WHATEVER long xあらゆる場所を認識し、long型はそこでは意味がありません。

于 2012-04-13T20:21:14.713 に答える
0

This code compile on my computer, using gcc 4.6.3 . The solution is to change compiler version to the latest.

But, it is a strange error, probably there is a compiler bug. If You don't want to change your compiler version, try putting private section at the begin of class. Hope that help.

于 2012-04-13T19:58:35.210 に答える