compilation error in objective-c file
I am developing a command line app which uses obj-c and c files together. In my obj-c file (say x.m), I use a struct which uses an interface and the interface uses a struct. This is easily handled in C++ with forward declarations but I need obj-c in my app.
I was wondering if someone can please shed some light on what I doing wrong.
Appreciate any help and thanks in advance.
typedef struct mystruct_s
开发者_C百科{
...
....
} mystruct;
struct abc ;
@interface abcDelegate:NSObject {
@public
struct abc *abc;
}
@end
struct abc
{
mystruct b
abcDelegate *abcdelegate;
};
I get the following error error:
expected specifier-qualifier-list before ‘mystruct’
You've forgot ;
should be
struct abc
{
mystruct b;
abcDelegate *abcdelegate;
};
If using .m file you must use c-style structs. such as
typedef struct mystruct_
{
...
} mystruct;
or
struct abc
{
struct mystruct b;
abcDelegate *abcdelegate;
};
If you want structs just like in c++ change your file extension to .mm to support c++
Almost there. Change the code to look like this:
struct abc
{
mystruct b;
abcDelegate *abcdelegate;
};
@interface abcDelegate:NSObject {
@public
struct abc *abc;
}
@end
精彩评论