c++ - VC++ : Weird compiler errors

标签 c++ visual-studio-2010 compiler-construction compiler-errors directx

我在使用 DirectX 的 visual studio 中工作,今天我遇到了一些奇怪的编译器错误,这些错误没有任何意义(至少对我而言)...

这些是我得到的错误:

错误 C2143:语法错误:缺少“;”前 '。' error C2059: 语法错误: ')'

我仔细检查了我的代码,没有发现任何拼写错误/错误(我可能是错的...)

我希望有人能告诉我错误通常意味着什么以及在哪里查看...

我会在下面放一些代码,并指出发生错误的行(以防你想检查)


额外信息: m_ImTexture2D 是一个成员结构。 Vertex.PosTex 是结构中的结构

GameManager.cpp:

(231): error C2143: syntax error : missing ';' before '.'
(231): error C2143: syntax error : missing ';' before '.'
(232): error C2143: syntax error : missing ';' before '{'
(233): error C2143: syntax error : missing ';' before '}'
(233): error C2143: syntax error : missing ';' before ','
(234): error C2143: syntax error : missing ';' before '{'
(234): error C2143: syntax error : missing ';' before '}'
(234): error C2143: syntax error : missing ';' before ','
(235): error C2143: syntax error : missing ';' before '{'
(235): error C2143: syntax error : missing ';' before '}'
(235): error C2143: syntax error : missing ';' before ','
(237): error C2143: syntax error : missing ';' before '{'
(237): error C2143: syntax error : missing ';' before '}'
(237): error C2143: syntax error : missing ';' before ','
(238): error C2143: syntax error : missing ';' before '{'
(238): error C2143: syntax error : missing ';' before '}'
(238): error C2143: syntax error : missing ';' before ','
(239): error C2143: syntax error : missing ';' before '{'
(239): error C2143: syntax error : missing ';' before '}'
(246): error C2143: syntax error : missing ')' before '.'
(246): error C2143: syntax error : missing ';' before '.'
(246): error C2143: syntax error : missing ';' before '.'
(246): error C2059: syntax error : ')'
(249): error C2065: 'vertices' : undeclared identifier

bool GameManager::GMLoadImage(Image** ppImage, const char* pkcFilePath, ImageDesc* pImDesc)
{
    (*ppImage) = new Image();

    ID3D11ShaderResourceView** ppColorMap = (*ppImage)->GetppColorMap();


/// CREATE SHADER RESOURCE VIEW (from file) ///
    HRESULT result = D3DX11CreateShaderResourceViewFromFileA(m_pDevice,
                                                             pkcFilePath,
                                                             0,
                                                             0,
                                                             ppColorMap,
                                                             0);
    if (FAILED(result)) {
        MessageBoxA(NULL,"Error loading ShaderResourceView from file","Error",MB_OK);
        return false;
    }


/// RECEIVE TEXTURE DESC ///
    ID3D11Resource* pColorTex;
    (*ppColorMap)->GetResource(&pColorTex);
    ((ID3D11Texture2D*)pColorTex)->GetDesc(&((*ppImage)->GetColorTexDesc()));
    pColorTex->Release();

/// CREATE VERTEX BUFFER ///
    D3D11_TEXTURE2D_DESC colorTexDesc = (*ppImage)->GetColorTexDesc();
    float halfWidth = static_cast<float>(colorTexDesc.Width)/2.0f;
    float halfHeight = static_cast<float>(colorTexDesc.Height)/2.0f;

/*231*/ Vertex.PosTex vertices[]=
/*232*/ {
/*233*/     {XMFLOAT3( halfWidth, halfHeight, 1.0f ),   XMFLOAT2( 1.0f, 0.0f )},
/*234*/     {XMFLOAT3( halfWidth, -halfHeight, 1.0f ),  XMFLOAT2( 1.0f, 1.0f )},
/*235*/     {XMFLOAT3( -halfWidth, -halfHeight, 1.0f ), XMFLOAT2( 0.0f, 1.0f )},
/*236*/
/*237*/     {XMFLOAT3( -halfWidth, -halfHeight, 1.0f ), XMFLOAT2( 0.0f, 1.0f )},
/*238*/     {XMFLOAT3( -halfWidth, halfHeight, 1.0f ),  XMFLOAT2( 0.0f, 0.0f )},
/*239*/     {XMFLOAT3( halfWidth, halfHeight, 1.0f ),   XMFLOAT2( 1.0f, 0.0f )}
        };

        D3D11_BUFFER_DESC vertexDesc;
        ZeroMemory(&vertexDesc,sizeof(vertexDesc));
        vertexDesc.Usage = D3D11_USAGE_DEFAULT;
        vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
/*246*/ vertexDesc.ByteWidth = sizeof(Vertex.PosTex)*6;

        D3D11_SUBRESOURCE_DATA resourceData;
/*249*/ resourceData.pSysMem = vertices;

    ID3D11Buffer** ppVBuffer = (*ppImage)->GetppVertexBuffer();
    result = m_pDevice->CreateBuffer(&vertexDesc,&resourceData,ppVBuffer);

    if (FAILED(result)) {
        MessageBoxA(NULL,"Error Creating VBuffer","Error",MB_OK);
        return false;
    }



/// SET POINTER TO IMAGEDESC
    ImageDesc** ppThisImDesc = (*ppImage)->GetppImageDesc();
    (*ppThisImDesc) = pImDesc;

    return true;
}

DxTetris.cpp:

(27): error C2143: syntax error : missing ')' before '.'
(27): error C2143: syntax error : missing ';' before '.'
(27): error C2143: syntax error : missing ';' before '.'
(27): error C2059: syntax error : ')'

bool DxTetris::LoadContent()
{
    GameManager::GMInitSingleton(m_pD3DDevice,m_pD3DContext,m_pBackBufferTarget);

    m_ImTexture2DDesc.Topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
/*27*/m_ImTexture2DDesc.VertexSize = sizeof(Vertex.PosTex);

    //.....(code goes on)
}

最佳答案

在 C++ 中,范围解析运算符是 :: , 而不是 .;因此,您需要使用 Vertex::PosTex 而不是 Vertex.PosTex

关于c++ - VC++ : Weird compiler errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7366913/

相关文章:

gcc 中的编译器优化

gcc - 可以在没有自由的情况下构建 binutils 吗?或者report_times可以禁用吗?

c++ - 从 'const char**' 到 'char* const*' 的无效转换

c - 拦截winsock recvfrom函数给出无效地址错误

c++ - Visual Studio 2010 Win32 应用程序无法在 Windows XP 上启动

c# - 获取错误 107 (net::ERR_SSL_PROTOCOL_ERROR):SSL 协议(protocol)错误

c - 什么编译器不支持 printf 标志中的 "%#x"样式?

android - Android.mk 文件中的 C++ 扩展

c++ - 如何使用 C++03 将一系列项目有效地插入到中间的 std::deque 中?

c++ - Visual Studio 中的 GCC 样式弱链接?