考慮以下代碼GCC錯誤,而使用代碼塊const的無符號長
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
由於男性
坦率地說,這樣一個想法並沒有把我的思想當作一個bug。謝謝!! – maress 2012-04-13 20:32:17
現在我想知道的是,宏是如何被首先定義的。 – rodrigo 2012-04-13 20:34:25
代碼正在生成,所以我不能告訴什麼類型的宏定義的類型。這是一個測試生成的代碼,看看它是否編譯 – maress 2012-04-13 20:37:47