C++ – Initializing a GLfloat

copenglvisual-studio-2008

Why can't I do this?

#include <gl/gl.h>

GLfloat posX;

 posX=0.0f;

Visual Studio says:

error C4430: missing type specifier –
int assumed. Note: C++ does not
support default-int

Best Answer

The text

 posX=0.0f;

is at global scope, so is treated as a declaration, not a statement. Consider:

#include "stdafx.h"
#include <windows.h>
#include <gl/gl.h>

GLfloat posY = 0.0f;

GLfloat posX;
posX = 0.0f;

GLfloat posZ;

int _tmain(int argc, _TCHAR* argv[])
{
    posZ = 0.0f;
    return 0;
}

Then posY, posZ compile fine, but posX shows the issue. Note the issue is nothing to do with GL; you'll get it if you replace GLfloat with plain old float.

Related Topic