vc++:奇怪的编译错误
VC++: Weird compiler errors
我在visual studio中使用DirectX工作,今天我得到了一些奇怪的编译器错误,这些错误没有任何意义(至少对我来说)…
这些是我得到的错误:
error C2143:语法错误:在'.'之前缺少';'错误C2059:语法错误:')'
我仔细检查了我的代码,没有发现任何拼写错误/错误(我可能错了…)
我希望有人能告诉我错误通常意味着什么,在哪里看…
我将在下面放置一些代码,并指出发生错误的行(以防您想检查)
额外信息:m_ImTexture2D是一个成员结构。顶点。postx是结构体
中的结构体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
。
相关文章:
- std::is_base_of表示ctor编译错误
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- 如何修复sfml c++代码编译错误
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- vscode下的Arduino代码出现意外编译错误
- 第三方 API 中的编译错误 - Visual Studio
- std::cout输出int时出现编译错误
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- 提升图广度优先搜索前置编译错误
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 我在C++中遇到了这个奇怪的编译错误
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 使用 std::enable_if 限制派生类的模板参数时出现编译错误
- 现代OpenGL和GLEW Libraray的编译错误
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- C ++程序编译错误,找不到/访问文件
- 使用直接大括号初始化时,C++ 编译错误"声明末尾的预期";"
- 为什么传递非静态成员函数会导致编译错误?