[英]Error C2228, though left of .x has a class
I am trying to call class function, while Visual Studio throws above error at me. 我试图调用类函数,而Visual Studio会向我抛出错误。 I have been calling another function in constructor and it works there.
我一直在构造函数中调用另一个函数,它在那里工作。
What is worth mentioning, is that GameLoop is static. 值得一提的是,GameLoop是静态的。 I have a strange feeling that this might be the cause.
我有一种奇怪的感觉,这可能是原因。 If it is, how do I make it work?
如果是,我该如何使它工作?
GameApp::GameApp()
{
winApi.CreateBasicWindow("---===| Test |===---", 1024, 768, WS_OVERLAPPEDWINDOW);
bool err = d3d.BasicInit(winApi.GetWindowHandle(),
winApi.GetInstance(),
1024,
768,
60,
1,
true);
if(!err)
MessageBox(0, "Could not initialize DirectX 10.", "Error!", MB_OK | MB_ICONERROR);
winApi.RunMessageLoop(GameLoop);
}
void GameApp::GameLoop()
{
D3DXCOLOR color(1.0f, 0.0f, 0.0f, 1.0f);
d3d.Redraw(color); // Error here
}
---- edit ----编辑
Error message 错误信息
Error 1 error C2228: left of '.Redraw' must have class/struct/union
If GameLoop
is static
, that means it can only access static
fields. 如果
GameLoop
是static
,那意味着它只能访问static
字段。 d3d
is probably not a static field. d3d
可能不是静态字段。
You probably made GameLoop static to keep a single instance of GameApp available throughout the code. 您可能使GameLoop静态,以便在整个代码中保持GameApp的单个实例。 To do that properly, read up on the singleton pattern, for it probably is what you are looking for.
要做到这一点,请阅读单身模式,因为它可能正是您所寻找的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.