3 Replies - 258 Views - Last Post: 28 October 2019 - 01:19 PM Rate Topic: -----

#1 Hejlia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-October 19

Undeclared Identifiers

Posted 27 October 2019 - 05:16 AM

I am following a tutorial from 2 years ago and there are a lot of undeclared identifier errors. I cannot find a way to fix these. I am using Visual Studio 2017, the code gives these errors:

Error C2065 'HANDLE': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 'hConsole
Error C2065 'hConsole': undeclared identifier
Error C2065 'GENERIC_READ': undeclared identifier
Error C2065 'GENERIC_WRITE': undeclared identifier
Error C2065 'NULL': undeclared identifier
Error C2065 'CONSOLE_TEXTMODE_BUFFER': undeclared identifier
Error C3861 'CreateConsoleScreenBuffer': identifier not found
Error C2065 'hConsole': undeclared identifier
Error C3861 'SetConsoleActiveScreenBuffer': identifier not found
Error C2065 'DWORD': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 'dwBytesWritten'
Error C2065 'dwBytesWritten': undeclared identifier
Error C2065 'wstring': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 'map'
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C2065 'map': undeclared identifier
Error C3861 'sinf': identifier not found
Error C3861 'cosf': identifier not found
Error C2065 'map': undeclared identifier

#include <iostream>
#include <Windows.h>
#include "pch.h"
using namespace std;

//Game Constants
int cScreenWidth = 120;
int cScreenHeight = 40;

float fPlayerX = 8.0f;
float fPlayerY = 8.0f;
float fPlayerA = 0.0f;

int cMapWidth = 16;
int cMapHeight = 16;

float fFOV = 3.14159 / 4.0;
float fDepth = 16.0f;

int main()
{
	//Create Screen Buffer
	wchar_t *screen = new wchar_t[cScreenWidth*cScreenHeight];
	HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
	SetConsoleActiveScreenBuffer(hConsole);
	DWORD dwBytesWritten = 0;

	//Create Map
	wstring map;

	map += L"################";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"#..............#";
	map += L"################";

	//Game Loop
	while (1)
	{
		for (int x = 0; x < cScreenWidth; x++)
		{
			//For each column, calculate the projected ray angle into world space
			float fRayAngle = (fPlayerA - fFOV / 2.0f) + ((float)x / (float)cScreenWidth) * fFOV;

			float fDistanceToWall = 0;
			bool HitWall = false;

			float fEyeX = sinf(fRayAngle); //Unit vector for ray in player space
			float fEyeY = cosf(fRayAngle);

			while (!HitWall && fDistanceToWall < fDepth)
			{
				fDistanceToWall += 0.1f;

				int TestX = (int)(fPlayerX + fEyeX * fDistanceToWall);
				int TestY = (int)(fPlayerY + fEyeY * fDistanceToWall);

				//Test if ray is out of bounds
				if (TestX < 0 || TestX >= cMapWidth || TestY < 0 || TestY >= cMapHeight)
				{
					HitWall = true;
					fDistanceToWall = fDepth;
				}
				else
				{
					//Ray is inbounds so test to see if the ray cell is a wall block
					if (map[TestY * cMapWidth + TestX] == '#')
					{
						HitWall = true;
					}
				}
			}

			//Calculate distance to ceiling and floor
			int cCeiling = (float)(cScreenHeight / 2.0) - cScreenHeight / ((float)fDistanceToWall);
			int cFloor = cScreenHeight - cCeiling;

			for (int y = 0; y < cScreenHeight; y++)
			{
				if (y < cCeiling)
				{
					screen[y*cScreenWidth + x] = ' ';
				}
				else if (y > cCeiling && y <= cFloor)
				{
					screen[y*cScreenWidth + x] = '#';
				}
				else
				{
					screen[y*cScreenWidth + x] = ' ';
				}
			}
		}

		screen[cScreenWidth * cScreenHeight - 1] = '\0';
		WriteConsoleOutputCharacter(hConsole, screen, cScreenWidth * cScreenHeight, { 0,0 }, &dwBytesWritten);
	}

	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Undeclared Identifiers

#2 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2394
  • View blog
  • Posts: 4,528
  • Joined: 30-May 10

Re: Undeclared Identifiers

Posted 27 October 2019 - 07:01 AM

Did you actually download the platform SDK along with your visual studio?

Ie, did you miss the "windows.h" not found error?

> #include "pch.h"
TBH, delete this line, then goto project settings and find the option for "pre-compiled headers" and turn it OFF!
It's nothing but a PITA option for newbies, and only really comes into it's own when compiling very large projects.
Was This Post Helpful? 1
  • +
  • -

#3 Hejlia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-October 19

Re: Undeclared Identifiers

Posted 27 October 2019 - 12:55 PM

I also thought it would be something along the lines of something missing from my project, but when I deleted the #include "pch.h" line and changed the properties... it fixed it. I am normally a Java/C# programmer so based on my knowledge I don't see how changing that would fix all my errors. Do you think that there was something wrong with the pch.h file that ruined the rest?

This post has been edited by Skydiver: 28 October 2019 - 01:17 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7132
  • View blog
  • Posts: 24,230
  • Joined: 05-May 12

Re: Undeclared Identifiers

Posted 28 October 2019 - 01:19 PM

When you use precompiled headers, everything declared before the precompiled header is ignored. The compiler assumes that everything you wanted to include is present in the "pch.h" file. So if your "pch.h" didn't include "windows.h", the compiler acts like you didn't include "windows.h".
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1