简体   繁体   English

错误C2228,虽然.x的左边有一个类

[英]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. 如果GameLoopstatic ,那意味着它只能访问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.

相关问题 错误:C2228:“”的左侧必须具有class / struct / union - Error: C2228: left of '' must have class/struct/union 错误C2228:“。x”的左侧必须具有class / struct / union - error C2228: left of '.x' must have class/struct/union 错误C2228:'.DXGI_MODE'的左边必须有class / struct / union Direct X. - error C2228: left of '.DXGI_MODE' must have class/struct/union Direct X 错误22错误C2228:'.size'的左侧必须具有class / struct / union - Error 22 error C2228: left of '.size' must have class/struct/union 错误C2228:'。Alloc'的左边必须有class / struct / union - error C2228: left of '.Alloc' must have class/struct/union 在异常情况下,C ++错误C2228('。''的左边必须有class / struct / union) - C++ Error C2228 (left of '.val' must have class/struct/union) in unusual circumstances 错误C2228:'。size'的左边必须有class / struct / union - error C2228: left of '.size' must have class/struct/union 获取错误代码C2228:“ ._ Ptr”的左侧必须具有class / struct / union - Getting error code C2228: left of '._Ptr' must have class/struct/union 错误C2228:'。words'的左边必须有class / struct / union - error C2228: left of '.words' must have class/struct/union 错误C2228:'.draw'的左边必须有class / struct / union - error C2228: left of '.draw' must have class/struct/union
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM