变量不是类的静态成员 [英] Variable is not a static member of class
问题描述
我正在研究GameKitHelper类,它主要是用C ++编写的,但是在某些地方,也可以在.mm文件中使用Objective-C.
I'm working on a GameKitHelper class, and it's mostly written in C++, but with Objective-C in some places as well, inside an .mm file.
我删除了一些隔离错误的功能:
I removed a bit of functionality to isolate the error:
void GameKitHelper::PopulateFriendScores(DynArray<GameCenterScore> *FriendScores)
{
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil)
{
leaderboardRequest.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardRequest.range = NSMakeRange(1,25);
[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error)
{
int i = 0;
printf("%d", i);
}];
}
}
我在这里遇到的错误是:
The error I get here is:
'int GameKitHelper::i' is not a static member of 'class GameKitHelper'
推荐答案
这是gcc错误.请参阅 Objective-C ++块与Objective-C块中的其中之一报告.
This is a gcc bug. See Objective-C++ block vs Objective-C block for one of many reports of it.
< soapbox>我建议尽可能避免使用Objective-C ++.编译起来很慢,运行起来很with肿(特别是使用ARC,因为它打开了 -fobjc-arc-exceptions ),编译器和调试器中的错误程序,而根据我的经验,在给这两个世界带来不利影响的情况下,大部分情况都是一团糟. C ++很好. Objective-C很好.只要保持它们之间的接口尽可能小即可. </soapbox>
<soapbox>I recommend avoiding Objective-C++ as much as possible. It's slow to compile, bloated to run (particularly with ARC since it turns on -fobjc-arc-exceptions), buggy in the compiler and the debugger, and mostly a mess in my experience giving the worst of both worlds. C++ is fine. Objective-C is fine. Just keep the interface between them as small as possible. </soapbox>
但是切换到clang 2.0可能会解决此特定问题.
But switching to clang 2.0 might fix this specific problem.
这篇关于变量不是类的静态成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!