使用const unsigned long的代码块时出现GCC错误(GCC error while using code blocks for const unsigned long)

编程入门 行业动态 更新时间:2024-10-25 18:27:34
使用const unsigned long的代码块时出现GCC错误(GCC error while using code blocks for 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上的代码块

谢谢你们

Consider this code

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

it does not compile and the compiler gives me this weird error.

||=== 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 ===|

when i remove the unsigned modifier, everything works fine. Probably i have been coding for the last 24 hours so i dont see whats wrong, and am struck. I dont want to sleep until that code compiles the way it is.

am using codeblocks on ubuntu and gcc 4.4.3

Thanks men

最满意答案

我敢打赌你有一个#define unsigned WHATEVER 。 或者您可能正在使用-Dunsigned=WHATEVER进行编译。

所以编译器看到const WHATEVER long x到处都是,而long类型在那里没有任何意义。

I would bet that you have a #define unsigned WHATEVER somewhere. Or maybe you are compiling with -Dunsigned=WHATEVER.

So the compiler sees const WHATEVER long x everywhere, and the long type makes no sense there.

更多推荐

本文发布于:2023-07-15 05:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110674.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   代码   long   unsigned   const

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!