使用Objective-C++; 我正在向iPhone(从Windows Mobile)移植一个项目,并使用ObjtoVC++来共享大量的C和C++代码。然而,在测试过程中,我偶然发现了一个奇怪而麻烦的问题,只有在设备上运行时才会出现。我已将问题代码提炼到一个新项目中,以证明其可重复性并便于共享 // MemoryTestAppDelegate.mm #include "MemoryTestAppDelegate.h" #include "Widget.h" @implementation MemoryTestAppDelegate @synthesize window; - (void)applicationDidFinishLaunching: (UIApplication*)application { Widget widget; const wchar_t wideHello[] = L"Hello, world!"; const char narrowHello[] = "Hello, world!"; widget.Go(); widget.Go(wideHello); [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end

使用Objective-C++; 我正在向iPhone(从Windows Mobile)移植一个项目,并使用ObjtoVC++来共享大量的C和C++代码。然而,在测试过程中,我偶然发现了一个奇怪而麻烦的问题,只有在设备上运行时才会出现。我已将问题代码提炼到一个新项目中,以证明其可重复性并便于共享 // MemoryTestAppDelegate.mm #include "MemoryTestAppDelegate.h" #include "Widget.h" @implementation MemoryTestAppDelegate @synthesize window; - (void)applicationDidFinishLaunching: (UIApplication*)application { Widget widget; const wchar_t wideHello[] = L"Hello, world!"; const char narrowHello[] = "Hello, world!"; widget.Go(); widget.Go(wideHello); [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end,iphone,stack,objective-c++,Iphone,Stack,Objective C++,//MemoryTestAppDelegate.h #进口 @接口MemoryTestAppDelegate:NSObject{ UIWindow*窗口; } @属性(非原子,保留)IBUIWindow*window; @结束 //Widget.h #包括 类小部件{ 公众: Widget(){}; ~Widget(){}; void Go()const{std::wcout就连苹果自己也承认,他们的模拟器和设备之间存在一些不同之处 遗憾的是,我无法帮助您解决您的问题,但是请记住,模拟器代码

//MemoryTestAppDelegate.h
#进口
@接口MemoryTestAppDelegate:NSObject{
UIWindow*窗口;
}
@属性(非原子,保留)IBUIWindow*window;
@结束

//Widget.h
#包括
类小部件{
公众:
Widget(){};
~Widget(){};

void Go()const{std::wcout就连苹果自己也承认,他们的模拟器和设备之间存在一些不同之处

遗憾的是,我无法帮助您解决您的问题,但是请记住,模拟器代码在mac处理器上编译和运行,就像在英特尔i386体系结构上编译和运行一样,当您为设备编译时,它是完全不同的,编译为使用设备的armv6

您发现的任何听起来像i386的怪癖都可能永远不会出现在设备上,反之亦然

// MemoryTestAppDelegate.h
#import <UIKit/UIKit.h>

@interface MemoryTestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow* window;
}

@property (nonatomic, retain) IBOutlet UIWindow* window;

@end
// Widget.h
#include <iostream>

class Widget {
public:
    Widget() { };
    ~Widget() { };

    void Go() const { std::wcout << L"Widget is GO." << std::endl; };
    void Go(const wchar_t* message) const { std::wcout << message << std::endl; };
};
// main.mm
#import <UIKit/UIKit.h>

int main(int argc, char* argv[]) {
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"MemoryTestAppDelegate");
    [pool release];
    return retVal;
}