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 上使用代码块
谢谢男人
我敢打赌你在某个地方有#define unsigned WHATEVER
。或者也许您正在使用-Dunsigned=WHATEVER
进行编译.
因此,编译器到处都可以看到const WHATEVER long x
,而long
类型在那里毫无意义。
这段代码在我的电脑上编译,使用 gcc 4.6.3 。解决方案是将编译器版本更改为最新版本。
但是,这是一个奇怪的错误,可能存在编译器错误。如果您不想更改编译器版本,请尝试将私有部分放在类的开头。希望有帮助。
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 在"C++代码"部分中,可能会写入两个字节
- 为什么 ifstream 文件中的换行符 - 当被此代码读取时 - 占用 2 个字节
- 带有C 代码的编辑组件字节
- C++Unicode:字节、代码点和图形
- 根据C++代码在 PHP 中创建字节数据并将其传递给套接字
- WideCharToMultiByte - Shift-JIS 代码页所需的大小和写入的字节数不同
- 你能在这个代码中找到 4 字节的内存泄漏吗?
- 当C#中的字节数组传递给结构中的非托管代码时,会发生什么情况
- 如何创建代码隔离大小应该是16 mb(字节码)大小的c ++程序
- 在编译/运行时将字符串文本的原始字节流入/流出Windows(非宽)执行字符集,以及ANSI代码页与UTF-8
- 如何以与字节序无关的方式读取 UTF-16 代码点的长度
- GCC 错误,同时对常量无符号长字节使用代码块
- AVX矢量化代码中的分段故障,GCC __attribute__对齐为32字节
- 编译lua代码,存储字节码,然后加载并执行它
- 这个代码如何使用64位乘法和模除法计算字节的奇偶校验
- 为什么我的代码无法读取 QTcpSocket 上可用的字节数?想法?
- 如何在代码中同时支持 Unicode 和多字节字符集
- Unicode 代码指向字节并反向:如何在C++中做到这一点
- 获取着色器字节代码传递给CreateVertexShader()