i am having objective c class, which i have a C function in it.
in that C function i want to call to ANOTHER c function in another class.
in the first class C function , i do this :
HelloWorldLayer *ran;
ran=[[HelloWorldLayer alloc] init];
[ran showDigital:BinaryWord];
when HelloWorldLayer is the other class, which have the C function :
void showDigital( int word[4])
and it declared also in the HelloWorldLayer.h .
in the first class, when i am trying to call the other function it says that showDigital function is not found.
is it has to do with the fact that its a C function ?
thanks.
First of all, the C function is not in the other class, it is merely in the same file as the other class. Objective-C classes have methods not functions.
So you can call your C function from anywhere provided you have an extern declaration of it. e.g. in
HelloWorldLayer.hIf you really want the function to be associated with instances of your class, you need to make it an Objective-C method. You can have that method be a thin wrapper for the original function if you like:
If you want to pretend that your C function is part of an object, you’ll need to add the receiver object as a parameter. You still won’t be able to access private instance variables directly though.