Objective-C のソースと Objective-C++ のソースをコンパイルするときに違いがあります。
test.h での Class1 と Class2 の宣言:
#import <Foundation/Foundation.h>
@interface Class1 {
}
@end
@interface Class2 {
}
@end
さて、これは test.m での Objective-C の実装です:
#import "test.h"
@implementation Class1
/* static member */
static int mystatic;
@end
@implementation Class2
/* static member */
static int mystatic;
@end
私はこのコマンドで正常にコンパイルします:
gcc -arch armv6 -isysroot /Developer/.../iPhoneOS5.0.sdk -x objective-c -c test.m
今、私はこの目的の C++ 実装 test.mm (まったく同じソース) を正確に使用します。
#import "test.h"
@implementation Class1
/* static member */
static int mystatic;
@end
@implementation Class2
/* static member */
static int mystatic;
@end
そして、このコマンドラインでコンパイルします (-x オプションの違い):
gcc -arch armv6 -isysroot /Developer/.../iPhoneOS5.0.sdk -x objective-c++ -c test.mm
しかし、私はエラーが発生します:
test.mm:11 error: redefinition if 'int mystatic'
ObjC ではなく ObjC++ でこのエラーが発生するのはなぜですか?