C++ 目标-C++;无法初始化id类型的参数<&燃气轮机;具有类型为MyType*\uu的左值,即使它符合协议

C++ 目标-C++;无法初始化id类型的参数<&燃气轮机;具有类型为MyType*\uu的左值,即使它符合协议,c++,objective-c,macos,objective-c++,C++,Objective C,Macos,Objective C++,我试图在OSX Objective-C++应用程序中使用AVKit,我有一个符合AVCaptureAudioDataOutputSampleBufferDelegate的VideoSource类,但编译器不接受它作为id类型的参数。我收到以下错误:Capture.mm:30:48:无法使用类型为“VideoSource*\uu strong”的左值初始化类型为“id”的参数。 这是我的代码: 捕获 我不确定这是怎么回事,因为似乎VideoSource应该是id类型。发生了什么事?您正在使用AVC

我试图在OSX Objective-C++应用程序中使用AVKit,我有一个符合AVCaptureAudioDataOutputSampleBufferDelegate的
VideoSource
类,但编译器不接受它作为
id
类型的参数。我收到以下错误:
Capture.mm:30:48:无法使用类型为“VideoSource*\uu strong”的左值初始化类型为“id”的参数。

这是我的代码:

捕获
我不确定这是怎么回事,因为似乎
VideoSource
应该是
id
类型。发生了什么事?

您正在使用
AVCaptureVideoDataOutput
,但您仅声明符合
AVCaptureAudioDataOutputSampleBufferDelegate
协议。协议使用相同的方法,因此您可以简单地更改协议的名称(如果您愿意,也可以同时采用这两种名称)

#ifndef ThreesAI_Capture_h
#define ThreesAI_Capture_h

#ifdef __OBJC__

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

@interface VideoSource : NSObject <AVCaptureAudioDataOutputSampleBufferDelegate>

@property AVCaptureSession *s;

- (id) init;

@end

#endif

void hello();

#endif
#import "Capture.h"

@implementation VideoSource

- (id) init {
    if (self = [super init]) {
        self.s = [[AVCaptureSession alloc] init];
        AVCaptureDevice *camera = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo][0];
        NSError *e;
        AVCaptureInput *cameraInput = [AVCaptureDeviceInput deviceInputWithDevice:camera error:&e];
        [self.s addInput:cameraInput];
        
        AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
        captureOutput.alwaysDiscardsLateVideoFrames = YES;
        dispatch_queue_t queue;
        queue = dispatch_queue_create("cameraQueue", NULL);
        [captureOutput setSampleBufferDelegate:self queue:queue];//Error on this line
        
        [self.s addOutput:captureOutput];
        [self.s startRunning];
    }
    return self;
}

- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
    NSLog(@"asdasd");
}

@end

void hello() {
    VideoSource *v = [[VideoSource alloc] init];
}