1

I have an abstract class in pure c++ (with a pure virtual function), and i have to implement that in a objective c class, how would i do that?

if i declare,

@interface MyClass : NSObject <MyOtherClass>

it throws an error telling protocol is not defined in MyOtherClass

Definition of C++ class:

class MyOtherClass
{
    virtual void myFunc() = 0;
};

Thanks in advance

Hari Krishna
  • 551
  • 6
  • 21
  • Maybe this question can help accomplish the same behavior: http://stackoverflow.com/questions/2262011/adding-c-object-to-objective-c-class – Alexandru Jan 28 '13 at 16:01

1 Answers1

1

Protocol is a feature of Objective-C, Not C++.

Your MyClass can't use any non objective-c class as its protocol.

As said by JeremyP

Make sure that any files that include that header are compiled as Objective-C++ either by changing the extension to .mm or by changing the file type to sourcecode.cpp.objcpp.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • thank you, so how would i make my class implement the functions from the other class? normal inheritance? i guess we dont have multiple inheritance also in objective c – Hari Krishna Jan 28 '13 at 16:02
  • @HariKrishna: You can't. Objective-C methods are completely different, syntactically and semantically, from C++ methods. They are not interchangeable. – newacct Jan 28 '13 at 18:26