代码之家  ›  专栏  ›  技术社区  ›  gargantuan

如何编写C++对象类的处理类

  •  0
  • gargantuan  · 技术社区  · 16 年前

    // --------------------------------------------------------------------

    我正在构建一个iPhone应用程序,并使用Openfeint SDK/Library/Framework(??)这是用C++编写的。

    我试着创建一个单例,希望能在正常情况下包含它的头。m文件,但这不起作用,我仍然需要创建包含头的文件。嗯

    这是我创造的单身汉。。。

    // --------------------------------------------------------------------
    //  OpenfeintController.h
    // --------------------------------------------------------------------
    #import <Foundation/Foundation.h>
    
    @interface OpenfeintController : NSObject {
    
        NSString *productKey, *secretKey, *displayName;
    
    }
    
    +(OpenfeintController*)sharedOpenfeintController;
    
    - (void) initializeWithProductKey:(NSString *)pKey andSecretKey:(NSString *)sKey andDisplayName:dName;
    
    - (void) launchOpenFeint;
    
    - (void) submitHighScoreToLeaderboard:(NSString *)leaderboardId;
    
    @end
    

    实施

    // --------------------------------------------------------------------
    //  OpenfeintController.mm
    // --------------------------------------------------------------------
    
    #import "OpenfeintController.h"
    #import "OpenFeint.h"
    
    static OpenfeintController *singletonOpenfeintController = nil;
    
    @implementation OpenfeintController
    
    +(OpenfeintController*)sharedOpenfeintController {
        @synchronized(self) {
            if (!singletonOpenfeintController) {
                singletonOpenfeintController = [[OpenfeintController alloc] init];
            }
        }
        return singletonOpenfeintController;
    }
    
    
    
    - (void) initializeWithProductKey:(NSString *)pKey andSecretKey:(NSString *)sKey andDisplayName:dName
    {
        //[OpenFeint initializeWithProductKey:pKey andSecret:sKey andDisplayName:dName andSettings:nil andDelegates:nil];
    }
    
    - (void) launchOpenFeint
    {
    
    }
    
    - (void) submitHighScoreToLeaderboard:(NSString *)leaderboardId
    {
    
    }
    
    @end
    
    2 回复  |  直到 16 年前
        1
  •  2
  •   Ciarán Walsh    16 年前

    OpenfeintController.h

    如果编译在执行此操作时出现错误,请发布错误,以便我们可以看到实际发生的情况。

        2
  •  0
  •   Ole Begemann    16 年前

    我做的事情与一个不同的C++库类似。 GeographicLib )而且它工作起来没有问题。只需确保在你的代码中没有C++代码或导入的C++标题。h文件。不过,我看不出你的代码有什么问题,所以恐怕我帮不了你。我没有OpenFeint的经验。

    推荐文章