Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Objective c 使用方法而不在标头中声明它们_Objective C_Oop - Fatal编程技术网

Objective c 使用方法而不在标头中声明它们

Objective c 使用方法而不在标头中声明它们,objective-c,oop,Objective C,Oop,最近我在代码中使用了不透明指针类型。我这样做是因为我想在我的Objc项目中使用C++代码,而不必将每个文件都更改为.mm. 我使用C++代码的方式是,我的C++代码作为一个.mm文件的成员有一个不透明指针。所有C++都隐藏在实现文件中。 在包含C++的类中,我需要导入一个现有的类“MyC类”。我可以在实现类中导入它,但是如果我试图在头中导入它,我会得到C++错误,称“ISO C++禁止声明“CARIGBUBEPRCPPrPrAPER”,没有类型“./p>”。 我“可以”在.mm文件中写入该方法

最近我在代码中使用了不透明指针类型。我这样做是因为我想在我的Objc项目中使用C++代码,而不必将每个文件都更改为.mm.

<>我使用C++代码的方式是,我的C++代码作为一个.mm文件的成员有一个不透明指针。所有C++都隐藏在实现文件中。

在包含C++的类中,我需要导入一个现有的类“MyC类”。我可以在实现类中导入它,但是如果我试图在头中导入它,我会得到C++错误,称“ISO C++禁止声明“CARIGBUBEPRCPPrPrAPER”,没有类型“./p>”。 我“可以”在.mm文件中写入该方法,并从标题中省略它,但我收到一条警告,说我的.mm文件可能不会响应该方法

这其中有很多都是全新的,所以我的术语可能有点不合适。如果我能以任何方式澄清我的问题,请告诉我

TLDR:如果没有在类Y头中声明方法,类X如何安全地调用类Y中的方法

//我的头球

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#define kBufferLength 5120

//#define "Myclass.h"
typedef struct ringbufferobj * RingBufferOBJ;


RingBufferOBJ newRingBufferOBJ();






@interface CARingBufferCPPWrapper : NSObject {

    RingBufferOBJ ringbuffer;
    NSThread  *producerthread;
    int duration;

}
@property (nonatomic, retain) NSThread *producerthread;
@property(nonatomic)int duration;

//-(void)myclassfunction(MyClass *)classref

@end
#导入
#进口
#定义kBufferLength 5120
//#定义“Myclass.h”
typedef结构ringbufferobj*ringbufferobj;
RingBufferOBJ newRingBufferOBJ();
@接口CarringBufferCppWrapper:NSObject{
环形缓冲区OBJ环形缓冲区;
NSThread*producerthread;
int持续时间;
}
@属性(非原子,保留)NSThread*producerthread;
@属性(非原子)int持续时间;
//-(void)myclassfunction(MyClass*)classref
@结束
//我的实现

#import "CARingBufferCPPWrapper.h"
#import "CARingBuffer.h"
#import <AudioToolbox/AudioToolbox.h>
#import "MyClass.h"

struct ringbufferobj
{
    CARingBuffer *ringbuffer;
    AudioBufferList *inputbuffer; 

    Float64 firstInputSampleTime;
    Float64 firstOutputSampleTime;
    Float64 inToOutSampleTimeOffset;





    BOOL producerthreadisrunning;
};

RingBufferOBJ newRingBufferOBJ(){
    RingBufferOBJ ringbuffer=(RingBufferOBJ)malloc(sizeof(struct ringbufferobj));

    return ringbuffer;
}


@implementation CARingBufferCPPWrapper
@synthesize producerthread;
@synthesize duration;


-(void)myclassfunction(MyClass *)classref
{

}
@end
#导入“CARingBufferCPPWrapper.h”
#导入“CARingBuffer.h”
#进口
#导入“MyClass.h”
结构ringbufferobj
{
CARingBuffer*ringbuffer;
音频缓冲列表*输入缓冲区;
Float64 firstInputSampleTime;
Float64 firstOutputSampleTime;
Float64到outsampletimeoffset;
BOOL生产商正在运行;
};
RingBufferOBJ newRingBufferOBJ(){
RingBufferOBJ ringbuffer=(RingBufferOBJ)malloc(sizeof(struct RingBufferOBJ));
返回环缓冲区;
}
@实现CARingBufferCPPWrapper
@合成产物;
@综合时长;
-(void)myclassfunction(MyClass*)classref
{
}
@结束

我不太确定你的问题是什么,因为我找不到任何真正有问题的东西。(我甚至
Cmd+F
'd表示“?”)。我想你是在问,你能做些什么来摆脱这个警告

-如果在调用它的方法之上声明了一个方法,那么应该没有警告。(方法按顺序编译)。要消除这样的警告,您必须向前声明方法签名。(这通常是在标题中,但我不认为有任何东西会阻止你在.m的顶部这样做)


这个转发声明是否允许从其他类调用该方法?除非它在头中,否则它仍然会从其他类生成警告。我认为它在运行时会工作得很好,虽然它在运行时确实工作。不过,我只是不高兴有这样的警告。我也稍微澄清了我的问题
-(void) methodA {
    ..do something
    [self methodB]; //Warning here because the compiler has not yet seen methodB

}

-(void) method B {
    ..[self methodA]; //No warning, compiler knows what methodA is at this point. 
}