Public Group

# Why is this a function instead of a constant?

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

## Recommended Posts

Using: Microsoft Visual C++ 6 This bug is really bothering me because I can't figure it out. The problem is the bold line. I get a compile error "illegal pure syntax", which I looked up on MSDN means the compiler thinks I am defining a pure virtual function and therefore must assign 0. But I thought I was making a constant?
#include <d3dx9.h>
#include "Helper.h"

#define PLANE_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)

class CPlane
{
public:
int Render();
CPlane(LPDIRECT3DDEVICE9 pD3DDevice, int width, int height);
virtual ~CPlane();

private:
static const int m_wTileSize = 32;

bool UpdateVertices();
HRESULT CreateVertexBuffer();
bool CreateIndexBuffer();

LPDIRECT3DDEVICE9 m_pD3DDevice;
LPDIRECT3DVERTEXBUFFER9 m_pVertexBuffer;
LPDIRECT3DINDEXBUFFER9 m_pIndexBuffer;
int m_wRows;
int m_wCols;
int m_numIndices;
int m_numVertices;
int m_numPolygons;

//Define a custom vertex
struct PLANE_CUSTOMVERTEX
{
FLOAT x, y, z;		//Coordinates in 3d space
DWORD colour;		//Color (not really needed)
FLOAT tu, tv;		//Texture coordinates
};
};

Is sleep deprivation getting to me and I'm missing something very obvious? Or is MSVC++ completely insane? (Hmmm, on post preview the plus signs aren't showing up. If you can't see them it's supposed to be C-plus-plus) edit: I was just looking at this, and the way I posted it, it looks as though I may have gotten confused about the line number since there is a virtual function 1 line above it- but that's NOT the case. I moved around that static const int to various places and immediately after the virtual function just happens to be where it is right now, the error is always on the static const int line.

##### Share on other sites
[Edit: I take back my answer...seems I was wrong.]

I tried compiling the line in question, and didn't seem to have any problems.

##### Share on other sites
Have you tried setting the virtual function = 0. I know I doesn't seem to be the line causing the problem, but you can get funny error messages sometime pointing to the wrong line.

Otherwise try removing the static keyword from infront of the const

##### Share on other sites
Try the following:

class CPlane  {        ...	static const int m_wTileSize;        ...};const int CPlane::m_wTileSize = 32;

I believe some older compilers require that syntax. You may want to consider using a newer one.

##### Share on other sites
Im telling you get rid of the old and install the new!!!
Visual C++ 2005 Express Edition

Hurry i think they only have 50 more copies available for download...!!! lol

##### Share on other sites
As everyone else has pointed out, it is a limitation of Visual Studio 6. Either write the constant as KrazeIke suggested - which won't make it a true compile-time constant, or use the enum trick:

class CPlane {   enum { m_wTileSize = 32 }};

Or better yet, listen to Bluseed and upgrade to VC8.

1. 1
2. 2
3. 3
4. 4
frob
20
5. 5
JoeJ
20

• 11
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632214
• Total Posts
3004858

×