如何创建指向结构的指针并对其进行类型转换?
有人可以告诉我我哪里出错了吗?我试图创建一个指向传递给函数的结构 aqData 的指针,并将其类型转换为 AQPlayerState 的结构类型。
我收到错误 - 使用未声明的标识符“AQPlayerState”和预期表达式
@implementation AudioPlayer
#define kNumberBuffers 3
struct AQPlayerState {
AudioStreamBasicDescription mDataFormat;
AudioQueueRef mQueue;
AudioQueueBufferRef mBuffers[kNumberBuffers];
AudioFileID mAudioFile;
UInt32 bufferByteSize;
SInt64 mCurrentPacket;
UInt32 mNumPacketsToRead;
AudioStreamPacketDescription *mPacketDescs;
bool mIsRunning;
};
static void HandleOutputBuffer (
void *aqData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer
) {
struct AQPlayerState *pAqData = (AQPlayerState *) aqData;
提前感谢您的帮助
can someone tell me where I'm going wrong here? I'm trying to create a pointer to the struct aqData that is passed in to the function, and type type cast it to a struct type of AQPlayerState.
I'm getting the errors - Use of undeclared identifier "AQPlayerState" and Expected expression
@implementation AudioPlayer
#define kNumberBuffers 3
struct AQPlayerState {
AudioStreamBasicDescription mDataFormat;
AudioQueueRef mQueue;
AudioQueueBufferRef mBuffers[kNumberBuffers];
AudioFileID mAudioFile;
UInt32 bufferByteSize;
SInt64 mCurrentPacket;
UInt32 mNumPacketsToRead;
AudioStreamPacketDescription *mPacketDescs;
bool mIsRunning;
};
static void HandleOutputBuffer (
void *aqData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer
) {
struct AQPlayerState *pAqData = (AQPlayerState *) aqData;
Thanks in advance for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信
Objective-C
的行为与C
相同。如果不是,这可能不适用于Objective-C
。C 中的结构通过其“全名”进行识别。
尝试或者,甚至更好,根本不施法。 C 编译器知道如何从void*
转换为任何其他指向对象的指针I believe
Objective-C
behaves asC
. If it doesn't this might not apply toObjective-C
.structs in C are recognized by their "full name".
Tryor, even better, don't cast at all. The C compiler knows how to convert fromvoid*
to any other pointer to object