views:

275

answers:

2

Hi Friends,

I want to use a Template class of C++ in my Objective C project. I have read that it is supported.

When I try to import the template class that is written in C++ I get lot of errors like
Cannot find protocol declaration for 'class' etc..

Can anyone give me a simple example of this.
Waiting for reply.

A: 

You are putting the objective c++ code in a .mm file? You need to use .mm files to tell the compiler its allows to parse c++ constructs in addition to objective-c and c.


You can't just change the name of a header file from .h to .mm - the name of the file containing the #include / #import directive needs to change.

// file: main.m
#import "cppclassdef.h" //will not work
#import "cppclassdef.mm" // also will not work. additionally will confuse XCode which will try to compile the .mm file by itself.

// file: main.mm
#import "cppclassdef.h" // this is how to do it.
Chris Becke
initially I had named it as .h File. But i tried to rename it with .mm but still it is not compiling
Ekra
Then youre going to need to include some code samples perhaps. How simple can you reduce the problem down to?
Chris Becke
A: 

I have the same issue, did you succeed to manage it? Thanks

AP