在 Objective C 中使用不透明指针时出现问题++
这个问题的答案解释了不透明指针是一个很好的选择在 Objective C++ 头文件中包含 C++ 成员变量的方法。我在尝试遵循该示例时遇到编译错误。这是我的标题中的相关代码,相应的编译器错误显示为注释:
struct ADSR_opaque; // error: forward declaration of 'struct ADSR_opaque'
@interface LoopyPulser : NSObject{
float _pulseRate;
UInt32 tickInterval;
UInt32 step;
InMemoryAudioFile * audioFilePlayer;
ADSR_opaque* env; // error: expected specifier-qualifier-list before 'ADSR_opaque'
Pattern * pattern;
float loopLengthRatio;
float volume;
}
我在这里做错了什么简单的事情吗?
The answer to this quesion explains that opaque pointers are a good way to include C++ member variables in an Objective C++ header. I'm getting compile errors when trying to follow the example. Here's the relevant code from my header, with the corresponding compiler errors shown as comments:
struct ADSR_opaque; // error: forward declaration of 'struct ADSR_opaque'
@interface LoopyPulser : NSObject{
float _pulseRate;
UInt32 tickInterval;
UInt32 step;
InMemoryAudioFile * audioFilePlayer;
ADSR_opaque* env; // error: expected specifier-qualifier-list before 'ADSR_opaque'
Pattern * pattern;
float loopLengthRatio;
float volume;
}
Is there something simple I'm doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对以下最小示例没有任何问题:
如果您在普通 Objective-C 文件(而不是 Objective-C++)中包含标头,则必须添加
struct
。或者使用 typedef:
I don't have any problem with the following minimal sample:
If you include the header in plain Objective-C files (not Objective-C++), you have to add
struct
.Alternatively use typedefs: