成员引用基类型“void”不是结构或联合 (OBJ-C)

Posted

技术标签:

【中文标题】成员引用基类型“void”不是结构或联合 (OBJ-C)【英文标题】:Member reference base type 'void' is not a structure or union (OBJ-C) 【发布时间】:2016-03-08 17:56:45 【问题描述】:

我正在使用 Apple 音频队列服务指南示例。https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQRecord/RecordingAudio.html#//apple_ref/doc/uid/TP40005343-CH4-SW1 通过示例,我得到了几个看不见的错误

#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);


;

构建失败,我不知道错误在哪里,因为它在文档中没有说明。感谢您的帮助

【问题讨论】:

请更新您的问题,将您的代码发布为文本,而不是图像。 【参考方案1】:

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

大概:

((AQRecorderState *) AQData)->mAudioFile

【讨论】:

好的,但是在哪里放置演员表,因为如果我这样做 (AQRecorderState*)AQData-&gt;mAudioFile 它仍然会给出相同的错误消息

以上是关于成员引用基类型“void”不是结构或联合 (OBJ-C)的主要内容,如果未能解决你的问题,请参考以下文章

成员引用基类型“类”不是结构或联合——Fixit 是不是将我引向了正确的方向?

目标 C 到 Swift 错误

自定义类型

分配给具有数组类型的表达式并请求非结构或联合中的成员[关闭]

实验报告

第八次试验报告