2012-06-06 1 views
0

BinaryWriterBinaryReader (from OpenFrameworks project on GitHub) iOS 5.x에서 Objective-C++의 C++ 클래스를 정의하고 사용하는 방법에 대해 누구에게도 말할 수 있습니까?iOS : Objective-C++에서 C++ 정의 및 사용

내가 무엇을 :

AppDelegate.h

#import <UIKit/UIKit.h> 
#import "Poco/BinaryWriter.h" 

@interface AppDelegate : UIResponder <UIApplicationDelegate>{ 
    Poco::BinaryWriter *_myBinaryWriter; 
} 

@property (strong, nonatomic) UIWindow *window; 

@end 

AppDelegate.mm

#import "AppDelegate.h" 

@implementation AppDelegate 

@synthesize window = _window; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    _myBinaryWriter = new Poco::BinaryWriter(NULL, NULL); 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

@end 

을하지만 mm 파일에 내가 컴파일 오류가 있습니다

No matching constructor for initialization of 'Poco::BinaryWriter'

은 무엇입니까 잘못하고 할 whar?

p.s. OpenFrameworks의 헤더 경로는 프로젝트 설정에서 구성되며 링커는 Poco 클래스를 볼 수 있습니다.

감사합니다.

답변

0

마시고 :: BinaryWriter (NULL, NULL)을, 당신은 수 std NULL로 변환 할 수 없습니다 : 당신은이

가 제대로 이러한 지침에 따라 그것을 만들 수 있습니다 :: ostream &. 당신이 실제로 당신이 실제로 같은 다른 표준 : : ostream에 파생 클래스를 사용하여 이동할 수 있습니다 작동하는지 확인하면

#import "AppDelegate.h" 
#include <iostream> 

@implementation AppDelegate 

@synthesize window = _window; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // Only for testing 
    _myBinaryWriter = new Poco::BinaryWriter(std::cout); 
    (*_myBinaryWriter) << 1 << 3.14f; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

@end 

:

은 표준 출력 (표준 : COUT)와 BinaryWriter를 테스트하려면 std :: ofstream (출력 파일 스트림).

+0

이 오류 메시지 : "이름 공간 'std'에 'cout'이라는 멤버가 없습니다. '카운트'를 의미합니까?" –

+0

맞습니다. #include .mm 파일을 추가해야합니다. 그래도 작동하는지 확인하는 것입니다. 나중에 자신의 std :: ostream을 사용하고 싶을 것이다. 그에 따라 내 대답이 업데이트됩니다. –

+0

당신은 진짜 Snip3r :)입니다. 제가 MemoryStream을 만들고 BinaryWriter와 함께 사용하도록 제안 할 수 있습니까? (코어 C# .NET 프로그래머와 Objc에 대한 나의 경험은 1 개월이다.) –

1

.m을 .mm으로 설정하면 C++를 사용할 수 있습니다.

그래서,

  • class.h
  • class.m

  • class.h
    • 에 class.mm에서
    _myBinaryWriter = new Poco::BinaryWriter(NULL, NULL); 
    

    이 줄은 마시고 :: binarywriter을 만듭니다. 오류

    No matching constructor for initialization of 'Poco::BinaryWriter'

    올바르게 만들지 않는다고 말합니다. BinaryWriter.h에서 해당 시그니처의 생성자가없는

    BinaryWriter(std::ostream& ostr, StreamByteOrder byteOrder = NATIVE_BYTE_ORDER); 
    /// Creates the BinaryWriter. 
    
    BinaryWriter(std::ostream& ostr, TextEncoding& encoding, StreamByteOrder byteOrder = NATIVE_BYTE_ORDER); 
    /// Creates the BinaryWriter using the given TextEncoding. 
    /// 
    /// Strings will be converted from the currently set global encoding 
    /// (see Poco::TextEncoding::global()) to the specified encoding. 
    
  • +0

    질문이 업데이트되기 전에 업데이트를했는데 아무런 효과가 없었습니다. 컴파일러 오류가 발생했습니다. –

    +0

    이 줄 _myBinaryWriter = new Poco :: BinaryWriter (NULL, NULL); 는 poco :: binarywriter를 만듭니다. 오류 'Poco :: BinaryWriter'초기화에 대한 일치하는 생성자가 없습니다. 올바르게 작성하지 않는다는 메시지가 나타납니다. – Pochi

    +0

    그 다음 올바른 형식의 클래스를 만드시겠습니까? –

    0

    이 질문은 일반적인 질문에 대한 답변이 아닙니다.

    최신 버전의 LLVM 컴파일러 (예 : Xcode 4).x) 인터페이스가 아닌 구현에 인스턴스 변수를 넣을 수 있습니다. 즉

    @interface AppDelegate : UIResponder <UIApplicationDelegate> 
    
    @property (strong, nonatomic) UIWindow *window; 
    
    @end 
    
    @implementation AppDelegate 
    { 
        Poco::BinaryWriter *_myBinaryWriter; 
    } 
    
    // etc 
    
    @end 
    

    이 인스턴스 변수가 이제 헤더를 가져오고 당신이 목표 - C++

    을하지 않고 다른 목표 - C 파일로 가져올 수 있도록 헤더는 이제 더 C++ 코드를 포함하지 않는 파일에서 숨겨진 것을 의미한다
    +0

    확실하지만, 나는 어쩌면 오류가 Property 선언에 합류했다고 생각하고 있었다. :) 어쨋든 고마워. –