7 Replies - 3531 Views - Last Post: 28 June 2011 - 05:55 AM Rate Topic: -----

#1 jammmie999  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 117
  • Joined: 01-April 09

Error C2065: Undeclared identifier

Posted 21 June 2011 - 08:14 AM

Hey guys,
Can you help me, I am new to C++. I am getting error "error C2065: 'level': undeclared identifier in game.cpp. Please help.
I have attached the project if you need it.

Level.h
#ifndef LEVEL_H
#define LEVEL_H

class Level
{
public:
	Level(DrawEngine *de, int width = 30, int height = 20);
	~Level();
}

#endif



Level.cpp
#include "level.h"
#include <stdlib.h>

Level::Level(DrawEngine *de, int w, int h)
{
	drawArea = de;

	width = w;
	height = h;

	player = 0;

	// create memory for our level
	//char **
	level = new char *[width];

	for(int x = 0; x < width; x++)
		level[x] = new char[height];

	// create the level
	createLevel();

	drawArea->setMap(level);
}

Level::~Level()
{
	//delete the memory for our level
	for(int x = 0; x < width; x++)
		delete [] level[x];

	delete [] level;
}



Game.cpp
#include "game.h"
#include <conio.h>
#include <Windows.h>
#include <iostream>

using namespace std;

//this is going to give us about 30 frames per second
#define GAME_SPEED = 1000 / 30;

bool Game::run(void)
{
	level = new Level(&drawArea, 30, 20);

//more code below, not relevent



Thanks

http://giggig.co.uk/evilMonkeys.rar - not allowd to attach .rar files?

Is This A Good Question/Topic? 0
  • +

Replies To: Error C2065: Undeclared identifier

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4133
  • View blog
  • Posts: 12,858
  • Joined: 25-December 09

Re: Error C2065: Undeclared identifier

Posted 21 June 2011 - 08:21 AM

You should probably include the include file for your class in game.cpp.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 jammmie999  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 117
  • Joined: 01-April 09

Re: Error C2065: Undeclared identifier

Posted 21 June 2011 - 08:30 AM

View Postjimblumberg, on 21 June 2011 - 06:21 PM, said:

You should probably include the include file for your class in game.cpp.

Jim

Level.h is included in game.h. Rather than being included in the game.cpp

This post has been edited by jammmie999: 21 June 2011 - 08:32 AM

Was This Post Helpful? 0
  • +
  • -

#4 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Error C2065: Undeclared identifier

Posted 23 June 2011 - 04:26 AM

Yes, but you shouldn't rely on indirect includes. Always include the headers you need for your code to work, even if they "should" be included already.
Was This Post Helpful? 0
  • +
  • -

#5 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Error C2065: Undeclared identifier

Posted 23 June 2011 - 06:30 AM

//Level.cpp
// create memory for our level
//char **
level = new char *[width];

[...]
//Game.cpp
level = new Level(&drawArea, 30, 20);

Is a global variable "level" declared anywhere? Or are these separate variables (as they probably should be)?

This post has been edited by Xupicor: 23 June 2011 - 06:32 AM

Was This Post Helpful? 0
  • +
  • -

#6 jammmie999  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 117
  • Joined: 01-April 09

Re: Error C2065: Undeclared identifier

Posted 26 June 2011 - 11:44 AM

View PostXupicor, on 23 June 2011 - 04:30 PM, said:

//Level.cpp
// create memory for our level
//char **
level = new char *[width];

[...]
//Game.cpp
level = new Level(&drawArea, 30, 20);

Is a global variable "level" declared anywhere? Or are these separate variables (as they probably should be)?

Yes, they are seperate variables
Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1362
  • View blog
  • Posts: 4,721
  • Joined: 19-February 09

Re: Error C2065: Undeclared identifier

Posted 26 June 2011 - 11:59 AM

You don't appear to have declared the level variable anywhere. I would suspect you need to add it to your class.

level = new char *[width];


Was This Post Helpful? 0
  • +
  • -

#8 jammmie999  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 117
  • Joined: 01-April 09

Re: Error C2065: Undeclared identifier

Posted 28 June 2011 - 05:55 AM

View Post#define, on 26 June 2011 - 09:59 PM, said:

You don't appear to have declared the level variable anywhere. I would suspect you need to add it to your class.

level = new char *[width];


Thank you, Have done now!

Problem Solved
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1