Objective-c using C + + classes

Source: Internet
Author: User

Read the Horky classmate's "mixed use objective-c,c++ and objective-c++" blog, I also have some ideas to record, easy to learn in the future

1.objective-c/C + +/C depth blending is not a good choice, prone to error, and poorly maintained, and when using C + + classes in objective-c code, we use equivalent objective-c types and functions to encapsulate C + + code (WRAP).

Do not refer to C + + header files in the 2.objective-c header file because there is no class keyword in objective-c. The compiler will report Unknown type name ' class '; Did you mean ' class '? error.

Here's a column for easy comprehension.

PlayerWindowController.h objective-ct Header File

#import <Cocoa/Cocoa.h>

@interface Playerwindowcontroller:nswindowcontroller

{

@private

void *_player; Define a void *

}

-(BOOL) Playurl: (nsurl *) URL;

@end

PLAYERWINDOWCONTROLLER.MM implementation

#import "PlayerWindowController.h"

#include <libkern/OSAtomic.h>//c++ header file

#include <AudioPlayer.h>//c++ class header files

#include <AudioDecoder.h>//c++ class header files

#define PLAYER (Static_cast<audioplayer *> (_player))

static void decodingstarted (void *context, const audiodecoder *decoder)

{

[(Playerwindowcontroller *) context Decodingstarted:decoder];

}

static void renderingstarted (void *context, const audiodecoder *decoder)

{

[(Playerwindowcontroller *) context Renderingstarted:decoder];

}

static void renderingfinished (void *context, const audiodecoder *decoder)

{

[(Playerwindowcontroller *) context Renderingfinished:decoder];

}

@implementation Playerwindowcontroller

-(ID) init

{

if (nil = = (self = [Super initwithwindownibname:@ "Playerwindow"])) {

[self release];

return nil;

}

_player = new Audioplayer ();

return self;

}

-(BOOL) Playurl: (nsurl *) URL

{

Audiodecoder *decoder = Audiodecoder::createdecoderforurl (reinterpret_cast<cfurlref> (URL));

if (nullptr = = decoder)

return NO;

player->stop ();

Register player Start/end messages to facilitate UI update

Decoder->setdecodingstartedcallback (decodingstarted, self);

Decoder->setrenderingstartedcallback (renderingstarted, self);

Decoder->setrenderingfinishedcallback (renderingfinished, self);  

return YES;

}

Objective-c using C + + classes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.