android - 如何使用 Android NDK 编译具有成员函数的结构?

标签 android c++ struct compiler-errors android-ndk-r5

<分区>

Possible Duplicate:
“expected ':', ',', ';', '}' or 'attribute' before '{' token” in Struct member function

我正在使用 android ndk-build 编译一个 C++ 库。当代码中包含一个定义了成员函数的结构时,我会收到编译错误。 此代码可与其他编译器一起编译。

示例代码:

typedef struct
{
    boolean current;
    int a;
    boolean IsCurrent() const
    {
      return current;
    }
} sampleStruct;

我得到的错误是 - “错误:在‘const’之前需要‘:’、‘,’、‘;’、‘}’或‘属性’” 如果我摆脱 const,错误是 - “错误:在‘{’标记之前需要‘:’、‘、’、‘;’、‘}’或‘属性’”

最佳答案

建议:

  1. boolean 替换为 bool,因为那是 C++ 的 bool 类型。
  2. 确保您没有使用 C 编译器进行编译。

风格建议: 请注意 typedef struct { ... } name; 在 C++ 中是一种过时的做法。只需编写 struct name { ... };,它使您能够编写构造函数和析构函数。

关于android - 如何使用 Android NDK 编译具有成员函数的结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10187491/

相关文章:

java - Android @Inject 和@InjectView 注解的含义

android - 找不到处理 Intent 错误的 Activity

c++ - 获取有向图中2个节点之间的所有路径

C - 无法在 while 循环之外打印结构

c - Windows 32 位下 C 结构中的内存对齐

c - 如何迭代结构中的所有项目?

android - "Android Library Update"阶段能否以某种方式加速?

android - 长按不弹出上下文菜单

c++ - OpenGL 计算着色器 - 奇怪的结果

c++ - 为什么控制台动画在 Windows 上这么慢? (有没有办法提高速度?)