成员参考基类型'void'不是结构或联合(OBJ-C)

问题描述:

我正在使用Apple Audio Queue Services指南示例。 https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQRecord/RecordingAudio.html#//apple_ref/doc/uid/TP40005343-CH4-SW1 通过我看不见几个错误成员参考基类型'void'不是结构或联合(OBJ-C)

#import <Foundation/Foundation.h> 
#import <AudioToolbox/AudioToolbox.h> 

const static int kNumberBuffers=3; //Sets the number of audio queue buffers to use 

typedef struct AQRecorderState{ 
    AudioStreamPacketDescription * mDataFormat; // An AudioStreamBasicDescription structure (from CoreAudioTypes.h) representing the audio data format to write to disk. This format gets used by the audio queue specified in the mQueue field. 
    AudioQueueRef mQueue; // The recording audio queue created by your application. 
    AudioQueueBufferRef mBuffers[kNumberBuffers]; //An array holding pointers to the audio queue buffers managed by the audio queue. 
    AudioFileID mAudioFile; // An audio file object representing the file into which your program records audio data. 
    UInt32 bufferByteSize; // The size, in bytes, for each audio queue buffer 
    SInt64 mCurrentPacket; // The packet index for the first packet to be written from the current audio queue buffer. 
    bool mIsRunning;  // Indicates whether queue is running. 
}AQRecorderState; 


static void HandleInputBuffer(
           void *AQData, // Typically, aqData is a custom structure that contains state data for the audio queue 

           AudioQueueRef inAQ, // The audio queue that owns this callback. 

           AudioQueueBufferRef inBuffer, //The audio queue buffer containing the incoming audio data to record. 

           const AudioTimeStamp *inStartTime, //The sample time of the first sample in the audio queue buffer (not needed for simple recording). 

           UInt32 inNumPackets, //The number of packet descriptions in the inPacketDesc parameter. A value of 0 indicates CBR data. 

           const AudioStreamPacketDescription *inPacketDesc // For compressed audio data formats that require packet descriptions, the packet descriptions produced by the encoder for the packets in the buffer. 
){ 

    AudioFileWritePackets(AQData->mAudioFile, // Member reference base type 'void' is not a structure or union 
          false, 
          inBuffer->mAudioDataByteSize, 
          inPacketDesc, 
          AQData->mCurrentPacket, // same here 
          &inNumPackets, 
          inBuffer->mAudioData); 


}; 

构建失败,我不知道哪里出错,因为它没有提到它在文档中的例子去。感谢您的帮助

+0

请张贴您的代码作为文本,而不是作为一个图像更新你的问题。 – rmaddy

您无法访问void *上的字段,您必须首先将其转换为特定类型。

大概:

((AQRecorderState *) AQData)->mAudioFile 
+0

好的,但在哪里放演员,因为如果我做'(AQRecorderState *)AQData-> mAudioFile'它仍然会给出相同的错误信息 – BsD

+0

谢谢你的工作嘿嘿 – BsD