C++ 函数调用-目标C
样本.hC++ 函数调用-目标C,c++,objective-c,C++,Objective C,样本.h class samples { declaration; } #include "samples.h" - (void)eventLog; #import "samples.h" samples.cpp #include "samples.h" void samples::buttonClick() { eventLog(); } void samples::eventLog() { //definition; } EventLog.h class samples
class samples
{
declaration;
}
#include "samples.h"
- (void)eventLog;
#import "samples.h"
samples.cpp
#include "samples.h"
void samples::buttonClick()
{
eventLog();
}
void samples::eventLog()
{
//definition;
}
EventLog.h
class samples
{
declaration;
}
#include "samples.h"
- (void)eventLog;
#import "samples.h"
EventLog.cpp
#include "samples.h"
void samples::buttonClick()
{
eventLog();
}
void samples::eventLog()
{
//definition;
}
这是Objective-C的等价物吗 样本.h
class samples
{
declaration;
}
#include "samples.h"
- (void)eventLog;
#import "samples.h"
samples.m
samples* a = [[samples alloc]init];
[a eventLog];
-(void)eventLog
{
//Definition;
}
EventLog.h
class samples
{
declaration;
}
#include "samples.h"
- (void)eventLog;
#import "samples.h"
EventLog.m
samples* a = [[samples alloc]init];
[a eventLog];
-(void)eventLog
{
//Definition;
}
不,这是错误的…使用以下行在sample.m中创建EventLog.m的实例:
EventLog *obj = [[EventLog alloc] init];
Then, use [EventLog eventLog];
看起来不错,不过你在做你的工作吗
#import <Foundation/Foundation.h>
@interface EventLog : NSObject {
}
- (void)eventLog;
@end
??如果没有“包装器”类,您肯定会遇到问题。而且,你的文件也很糟糕。如果
samples.h
实现了eventLog
,则不应该在eventLog.m
中实现它。那将是samples.m的工作。有关可能的结构,请参阅上面的示例。我没有在eventLog.h文件中声明函数eventLog()。我正在添加声明此eventLog()函数的标头。我编译了此函数,但没有收到任何错误。但我不确定此声明是否被称为[事件日志]它将在sample.m中搜索函数定义,而不是在EventLog中。m不是吗?但您将消息发送到对象,而不是“定义”它的文件。