Jump to content
  • Advertisement
Sign in to follow this  
polaris2013

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
[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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!