VC++: Weird compiler errors - c++

I'm working in visual studio with DirectX and today I've gotten some weird compiler errors that don't make any sense (to me at least)...
These are the errors I get:
error C2143: syntax error : missing ';' before '.'
error C2059: syntax error : ')'
I've double checked my code and didn't spot any typos/mistakes (I could be wrong...)
I'm hoping that someone can tell me what the error usually means and where to look...
I'll put some code below with the indication of the line where the errors occur (in case you want to check)
Extra info:
m_ImTexture2D is a member struct.
Vertex.PosTex is a struct within a struct
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)
}

In C++, the scope resolution operator is ::, not .; consequently, you need to use Vertex::PosTex rather than Vertex.PosTex.

Related

How can I use inline assembly in 64bit for float->int conversion with rounding towards -Infinity?

I was trying to convert 32bit game client to 64bit. But I can't compile, because the client has an inline ASM code, 64bit doesn't support __asm inline. So I can't find a solution for this. I hope I can get into this community.
define inline code:
#define PR_FLOAT_TO_INTASM __asm \
{ \
__asm fld PR_FCNV \
__asm fistp PR_ICNV \
}
#define PR_FLOAT_TO_INT(inreal, outint) \
{ \
PR_FCNV = (inreal); \
PR_FLOAT_TO_INTASM; \
(outint) = PR_ICNV > PR_FCNV ? PR_ICNV - 1 : PR_ICNV; \
}
Example code using:
float CMapOutdoor::GetTerrainHeight(float fx, float fy)
{
if (fy < 0)
fy = -fy;
long lx, ly;
PR_FLOAT_TO_INT(fx, lx);
PR_FLOAT_TO_INT(fy, ly);
WORD usCoordX, usCoordY;
usCoordX = (WORD)(lx / CTerrainImpl::TERRAIN_XSIZE);
usCoordY = (WORD)(ly / CTerrainImpl::TERRAIN_YSIZE);
BYTE byTerrainNum;
if (!GetTerrainNumFromCoord(usCoordX, usCoordY, &byTerrainNum))
return 0.0f;
CTerrain* pTerrain;
if (!GetTerrainPointer(byTerrainNum, &pTerrain))
return 0.0f;
return pTerrain->GetHeight(lx, ly);
}
Error code:
error C2146: syntax error : missing ';' before identifier 'PR_ICNV'
error C2146: syntax error : missing ';' before identifier 'fistp'
error C2146: syntax error : missing ';' before identifier '}'

Getting syntax error in GLSL array constructor not supported

with this code
var mat_add = gpu.createKernel(function(A, B) {
var sum = [];
for (var i=0; i<3; i++) {
sum.push(A[this.thread.y][i] + B[i][this.thread.x]);
}
return sum;
}).dimensions([2, 2]);
I am getting this error:
An error occurred compiling the shaders: ERROR: 0:141: '' : array size must be greater than zero
ERROR: 0:141: '[]' : array constructor supported in GLSL ES 3.00 and above only
ERROR: 0:141: 'constructor' : array constructor needs one argument per array element
ERROR: 0:141: '=' : Invalid operation for arrays
ERROR: 0:141: '=' : cannot convert from 'const array[1] of float' to 'highp float'
ERROR: 0:145: 'sum' : undeclared identifier
ERROR: 0:145: '' : methods supported in GLSL ES 3.00 and above only
ERROR: 0:145: 'push' : invalid method
This actually works:
var mat_mult = gpu.createKernel(function(A, B) {
var sum = 0;
for (var i=0; i<3; i++) {
sum += A[this.thread.y][i] * B[i][this.thread.x];
}
return sum;
}).dimensions([2, 1]);
Does anyone know how to fix this syntax error?
Thanks
i created python code to convert list into function getters : https://github.com/MhadhbiXissam/GLSL_LIST

qt creator issue when include std string library

I have this function. I created it with libxml2 and std::string library.
#ifndef KNIHOVNA_H
#define KNIHOVNA_H
#include <string>
#include <libxml/tree.h>
std::string hledaniString(int index,xmlDocPtr sharedString)
{
std::string Istring;
xmlAttrPtr attr;
xmlChar *attrValue;
xmlNodePtr nodeLevel1 = sharedString->children;
int maxValue;
int aIndex;
attr = xmlHasProp(nodeLevel1, (const xmlChar*)"uniqueCount");
if (attr !=NULL)
{
attrValue = xmlGetProp(nodeLevel1, (xmlChar *)"uniqueCount");
}
else return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
nodeLevel1 = nodeLevel1->children;
maxValue = atoi((const char *) attrValue);
xmlFree(attrValue);
if (maxValue<=index) return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
for (aIndex = 0;aIndex < index; aIndex++ )
{
nodeLevel1 = nodeLevel1->next;
}
nodeLevel1 = nodeLevel1->children;
attrValue = xmlNodeGetContent(nodeLevel1);
xmlFree(attrValue);
attrValue = xmlNodeGetContent(nodeLevel1);
Istring = (char *) attrValue;
xmlFree(attrValue);
return Istring;
#endif // KNIHOVNA_H
I use it in Code Block project where is everything ok and in qt creator project where I get these errors:
/usr/include/c++/4.8/string:38: In file included from /usr/include/c++/4.8/string:38:0,
/usr/include/c++/4.8/bits/stl_relops.h:-1: In function 'std::string getString(int, xmlDocPtr)':
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected '=' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected identifier before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected primary-expression before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/home/daffy/qt projektz/revize/main.cpp:15: error: expected '}' at end of input
Could someone help me please ?

c++ Undeclared identifier inside operator function

I'm creating a "date" class in c++, which holds day, month and year variables and bunch of operator functions to use it with.
I have a date.h header and date.cpp for my class and one of the operator functions in date.cpp is giving me bunch of errors.
date.cpp
(I want this operator-function to count days added and return a new date object and avoid changes to the original date object.)
date date::operator+(long days) const{
date dTemp( date.getDay(), date.getMonth(), date.getYear() );
for(int i=0;i<days;i++){
//If days go over a months day count.
if(dTemp.getDay() >= daysInMonth[dTemp.getMonth()]){
dTemp.setDay(1);
if(dTemp.getMonth() < 12){
dTemp.setMonth(dTemp.getMonth() + 1);
}
else{
//Changing a year.
dTemp.setMonth(1);
dTemp.setYear(dTemp.getYear() + 1);
}
}
else{
dTemp.setDay(dTemp.getDay() + 1);
}
}
return dTemp;
}
Errors:
1>h:\c++\teht21\teht20\date.cpp(74): error C2143: syntax error : missing ')' before '.'
1>h:\c++\teht21\teht20\date.cpp(74): error C3484: syntax error: expected '->' before the return type
1>h:\c++\teht21\teht20\date.cpp(74): error C2061: syntax error : identifier 'getDay'
1>h:\c++\teht21\teht20\date.cpp(79): error C2065: 'dTemp' : undeclared identifier
1>h:\c++\teht21\teht20\date.cpp(79): error C2228: left of '.getDay' must have class/struct/union
1> type is ''unknown-type''
Line 74 is:
date dTemp( date.getDay(), date.getMonth(), date.getYear() );
Any help is hugely appreciated.
If you need to see more code, let me know.
If getDay(), getMonth(), getYear() are member functions and you want to call them on this then change:
date dTemp( date.getDay(), date.getMonth(), date.getYear() );
to:
date dTemp( getDay(), getMonth(), getYear() );
Probably you want to call static methods here:
date dTemp( date.getDay(), date.getMonth(), date.getYear() );
So:
date dTemp( date::getDay(), date::getMonth(), date::getYear() );

Compile Error in VS2010 while testing LinkedLists

I'm doing some tests to a LinkedList, that has two pointers: one point to the next item in the list and the other point to a random node within the list.
Here is the code:
struct Node
{
Node* pNext; // a pointer to the next node in the list
Node* pReference; // a pointer to a random node within the list
int number; // an integer value
};
/**
* This version works for small/medium lists, using recursion.
*/
Node* duplicateList(Node* n)
{
if (n == NULL) return NULL;
return new Node()
{
number = n->number,
pNext = duplicateList(n->pNext),
pReference = duplicateList(n->pReference)
};
}
I'm getting the following errors (VS2010):
d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(21): error C2143: syntax error : missing ';' before '{'
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(22): error C2065: 'number' : undeclared identifier
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(23): error C2065: 'pNext' : undeclared identifier
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(24): error C2065: 'pReference' : undeclared identifier
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(25): error C2143: syntax error : missing ';' before '}'
Thanks.
This bit is not valid C++:
return new Node()
{
number = n->number,
pNext = duplicateList(n->pNext),
pReference = duplicateList(n->pReference)
};
Change it to this:
Node* pNode = new Node();
pNode->number = n->number;
pNode->pNext = duplicateList(n->pNext);
pNode->pReference = duplicateList(n->pReference);
return pNode;
Add a constructor to Node:
struct Node
{
Node(Node* next, Node* ref, int number) : pNext(next), pReference(ref), number(number) { }
// ...
};
then
return new Node(a, b, c);