here is the code:

struct Vertex
{
	Vertex(){}
	Vertex(float x, float y, float z)
	{
		_x = x;  _y = y;  _z = z;
	}
	float _x, _y, _z;
	static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;

firstly, does the word static in the struct Vertex declaration indicate that FVF can only be initialized once? im really unsure

and underneath the structure declaration what is happening in relation to the Vertex::FVF constant,

Thanks for your help

Recommended Answers

All 2 Replies

Greetings,

const keyword
Variables declared with ‘const’ become constants and cannot be altered by the program.

static keyword
The most commonly used and understood purpose of the
'static' keyword is to create a persistent variable.

If you declare a variable as static (by putting the static
keyword in front of its declaration), it will be initialised
the first time the function or block is run. But, unlike
normal variables, it will not be destroyed when the function
or block returns. The next time the function or block is
executed, that variable will still contain its previous
value. This is known as 'persistence' - the value persists
even while it's out of scope.

static const DWORD FVF;

Here you are creating a static constant variable. It exists about, and cannot be changed.

const DWORD Vertex::FVF = D3DFVF_XYZ;

This code sets the constant variable outside the Vertex class, hence Vertex::.

- Stack Overflow

i still dont understand thou why it is declared like

const DWORD Vertex::FVF = D3DFVF_XYZ;

why not just

Vertex::FVF = D3DFVF_XYZ;

please could you explain further

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.