Search code examples
c++iosobjective-cxcode

Got so many error when compiled C++ in Xcode


I try to add c++ class into my iphone project.but I got so many error message

for example , in MyClass.h

struct DefaultData{
    char id[32];
    char name[256];
};


struct DefaultDataList{
    int size;
    //Here got a error1 : **Expected specifier-qualifier-list before "DefaultData"**
    DefaultData *dataList;
};

//Here got error 2:**Expected identifier or'(' before ':' token**
struct BookData:DefaultData{
    char class_id[32];
    char country_id[32];
    char author[128];
    char file_type[32];
    char file_size[32];
    :
    :
};

Does anyone know what's going on here?

beacuse the c++ is not create by me ...

Does it have any tutorial is about How to import C++ class to object-c?


Solution

  • Objective-C does not support C++ classes - you need Objective-C++ to mix C++ with Objective-C.

    As for your errors, the code you've posted is neither valid C nor C++.