0

iOS 5.x- > Objective-C ++でBinaryWriterBinaryReaderGitHubのOpenFrameworksプロジェクトから)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ファイルではコンパイルエラーがあります:

'Poco::BinaryWriter'の初期化に一致するコンストラクターがありません

何が間違っていて、何をすべきか?

OpenFrameworksのヘッダーへのpsパスはプロジェクトの設定で構成され、リンカーはPocoクラスを見ることができます。

ありがとうございます。

4

3 に答える 3

1

.mを.mmに設定するだけで、c++を使用できます。

だから、から

  • class.h
  • class.m

  • class.h
  • class.mm

この行

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

poco::binarywriterを作成します。エラー

'Poco::BinaryWriter'の初期化に一致するコンストラクターがありません

正しく作成していないと言います。

次のガイドラインに従って適切に作成する必要があります。

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.
于 2012-06-06T08:11:39.853 に答える
0

Poco :: BinaryWriter(NULL、NULL)BinaryWriter.hにはその署名を持つコンストラクターはなく、NULLからstd :: ostream&に変換することはできません。

BinaryWriterを標準出力(std :: cout)でテストするには:

#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

これが実際に機能していることを確認したら、std :: ofstream(出力ファイルストリーム)などの他のstd::ostream派生クラスを実際に使用することに進むことができます。

于 2012-06-06T09:19:42.830 に答える
0

これはあなたの特定の質問に対する答えではなく、一般的なアドバイスです。

LLVMコンパイラの最新バージョン(つまりXcode 4.x)では、インターフェイスではなく、実装にインスタンス変数を配置できます。すなわち

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

@implementation AppDelegate
{
    Poco::BinaryWriter *_myBinaryWriter;
}

// etc

@end

つまり、インスタンス変数はヘッダーをインポートするファイルから非表示になり、ヘッダーにはC ++コードが含まれないため、Objective-C++にすることなく他のObjective-Cファイルにインポートできます。

于 2012-06-06T09:29:26.897 に答える