Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 函数调用-目标C_C++_Objective C - Fatal编程技术网

C++ 函数调用-目标C

C++ 函数调用-目标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

样本.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
{
 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不是吗?但您将消息发送到对象,而不是“定义”它的文件。