MatterGoal
MatterGoal

Reputation: 16430

Adding a C++ Header to Objective-C project

I've got a strange error working with Photoshop connection API in OSx. I need to include the header of a cpp file to my project... I start from the adobe example and I included the code in this way:

#include "PSCryptor.h" 

which contains the PSCryptor class :

class PSCryptor
{
    public:
...

As soon as i try to use PSCrypor object, like with this code

static PSCryptor *sPSCryptor = NULL;

I get this error:

Unknown type name 'class'; did you mean 'Class'?

Could you help me to understand which is my error?

Upvotes: 0

Views: 81

Answers (1)

Chuck
Chuck

Reputation: 237010

The file is being included in Objective-C files — that is, they have the extension ".m" or they are specifically configured to be compiled as Objective-C (probably the former). Thus, the compiler tries to interpret the code as Objective-C, but C++ is not valid Objective-C, so it complains.

What you need to do is use Objective-C++ instead. Simple fix: change the extension of the files that use that header from ".m" to ".mm".

Upvotes: 2

Related Questions