我是Objective-C的新手。我正在将C ++代码移植到Objective-C中。我有
这个函数调用eventLog()
samples.cpp
我已宣布这一点
samples.h
中的函数。我有它
EventLog.cpp
上的定义
包括samples.h
头文件。
samples.h
class samples
{
declaration;
}
samples.cpp
#include "samples.h"
void samples::buttonClick()
{
eventLog();
}
EventLog.h
#include "samples.h"
EventLog.cpp
void samples::eventLog()
{
//definition;
}
这是Objective-C的等价物吗?
samples.h
- (void)eventLog;
samples.m
samples* a = [[samples alloc]init];
[a eventLog];
EventLog.h
#import "samples.h"
EventLog.m
-(void)eventLog
{
//Definition;
}
答案 0 :(得分:1)
看起来不错,除非你在做
#import <Foundation/Foundation.h>
@interface EventLog : NSObject {
}
- (void)eventLog;
@end
和
#import "EventLog.h"
#import "Samples.h"
@implementation EventLog
- (void)eventLog
{
//definition
}
@end
?如果您没有“class wrappers”类,那么您一定会遇到问题。此外,您的文件非常棘手。如果samples.h
实施eventLog
,则不应在EventLog.m
中实施。那将是samples.m
的工作。有关可能的结构,请参阅上面的示例。
答案 1 :(得分:0)
不,这是错的...... 使用以下行:
在sample.m中创建EventLog.m的实例EventLog *obj = [[EventLog alloc] init];
Then, use [EventLog eventLog];