# DirectX Errors

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am getting some weird errors from the following code:
//CODE I AM GETTING ERRORS FROM

CUSTOMVERTEX vertices[4];

vertices[0] = CreateVertex(150.0f, 50.0f, 0.5f, 0, 0);
vertices[1] = CreateVertex(250.0f, 50.0f, 0.5f, 1, 0);
vertices[2] = CreateVertex(250.0f, 150.0f, 0.5f, 1, 1);
vertices[3] = CreateVertex(150.0f, 150.0f, 0.5f, 0, 1);

/**
*D3DUtils.h
*Contains utility methods for D3D.
*Author: Kane McGovern
*Revision: 25 November 2004
*/

#ifndef D3DUtils
#define D3DUtils

//CUSTOM VERTEX//////////////////////
struct CUSTOMVERTEX
{
float x, y, z;
float tu, tv;
};	//close CUSTOMVERTEX struct

CUSTOMVERTEX CreateVertex(float newX, float newY, float newZ, float newTu, float newTv)
{
CUSTOMVERTEX vertex;

vertex.x = newX;
vertex.y = newY;
vertex.z = newZ;
vertex.tu = newTu;
vertex.tv = newTv;

return vertex;
}	//close CreateVertex method

#endif


The errors I am getting are: C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(48) : error C2466: cannot allocate an array of constant size 0 C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(48) : error C2501: 'vertices' : missing storage-class or type specifiers C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(48) : error C2371: 'vertices' : redefinition; different basic types C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(46) : see declaration of 'vertices' C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(48) : error C2440: 'initializing' : cannot convert from 'struct CUSTOMVERTEX' to 'int []' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(49) : error C2501: 'vertices' : missing storage-class or type specifiers C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(49) : error C2369: 'vertices' : redefinition; different subscripts C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(46) : see declaration of 'vertices' C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(49) : error C2440: 'initializing' : cannot convert from 'struct CUSTOMVERTEX' to 'int [1]' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(50) : error C2501: 'vertices' : missing storage-class or type specifiers C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(50) : error C2369: 'vertices' : redefinition; different subscripts C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(46) : see declaration of 'vertices' C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(50) : error C2440: 'initializing' : cannot convert from 'struct CUSTOMVERTEX' to 'int [2]' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(51) : error C2501: 'vertices' : missing storage-class or type specifiers C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(51) : error C2369: 'vertices' : redefinition; different subscripts C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(46) : see declaration of 'vertices' C:\Kool\Game Dev\D3DDemo\d3ddemo.cpp(51) : error C2440: 'initializing' : cannot convert from 'struct CUSTOMVERTEX' to 'int [3]' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Any ideas what is going on?

##### Share on other sites
The usual check list :

- have you included the header file ?
- Are you sure that D3DUtil isn't used already by DX itself ?
- Is CUSTOMVERTEX already defined in a different manner ?

Seems that the header isn't included as should.

Best regards,
Metron

##### Share on other sites
I checked all that and am still getting the same errors. It's probably something really simple but I just can't work it out. Dang it.

##### Share on other sites
You're going to need to post some more code before I can figure exactly what's going on. One thing is that it looks like you're trying to initialise the array by calling functions outside of any execution block. Also, if you're defining that CreateVertex() function in the header file and it's not inline you'll probably have link errors if the header is included anywhere else. There may be other issues but I can't see from that snippet.

-Mezz

##### Share on other sites
my guess is that the code is at global scope, ie: not in a function. The code is then interpreted as a new array missing a type, so it's assuming int, then complaining that you've asked for it to be 0 size, then complaining that you're not assigning it int values.

Then another array.. etc.

It's not expecting code because it's not in a function.

##### Share on other sites
Quote:
 Original post by MezzOne thing is that it looks like you're trying to initialise the array by calling functions outside of any execution block.
D'oh. Beaten by 1 whole second! ;)

##### Share on other sites
Jeeeesus...I knew it would be something simple...

What a weiner I am...like you have said, the code is in global space and not in a function...thanks yall