# [Solved] Here's a real puzzler...

This topic is 3844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I try not to use this site just for debugging help, but this is one of those times I'm well and truly stumped. Take a look at this compiler output (this is VS 2005 Express):
1>Compiling...
1>ScreenRepository.cpp
1>c:\documents and settings\...\source\humangameview.h(47) : error C2065: 'ScreenRepository' : undeclared identifier
1>HumanGameView.cpp
1>c:\documents and settings\...\source\logiclayer.h(31) : error C2065: 'HumanGameView' : undeclared identifier


Short version: There's absolutely no way those identifiers should be undeclared in the files it complains about. They've been there and working for a long time. Longer version: These suddenly started appearing while I was working in other parts of the program that don't interact with these classes. When it compiles the .cpp file for the class ScreenRepository, it says there's an error in HumanGameView.h. Here's the thing: HumanGameView.h correctly includes ScreenRepository.h, and it's been using the class fine for ages! ScreenRepository.h doesn't include HumanGameView.h, so why does the error crop up when it's ScreenRepository.cpp being compiled? Same for LogicLayer and HumanGameView. Can anyone shed some light on what's going on? [Edited by - Sol Blue on February 11, 2008 12:50:26 PM]

##### Share on other sites
Quote:
 Original post by Sol BlueScreenRepository.h doesn't include HumanGameView.h, so why does the error crop up when it's ScreenRepository.cpp being compiled? Same for LogicLayer and HumanGameView.
They probably include something that DOES include it. What do they include?

##### Share on other sites
Please tell us what you've tried (such as a rebuild all?) so we don't suggest things you've already tried.
Then, please post some code or at least give a through description of what files include what other files and where things are defined etc.
Don't worry, there should be a simple explanation[smile].

##### Share on other sites
Quote:
 Original post by iMalcDon't worry, there should be a simple explanation[smile].

Eheh, I hope so. ^^

Cleaning and rebuilding haven't helped.

Is it probably a problem with #includes? I'm pretty sure I don't have any cyclic dependencies; I've solved those before.

There's way too much code to show, unfortunately. I can give parts of the mentioned .h files, though:

// ScreenRepository.h// This file only has a few includes. None of them include this file or// HumanGameView.h.#include "D3DUtil.h"#include "ResourceManager.h"#include "Screen.h"

// HumanGameView.h// This file is the only one that includes ScreenRepository.h.// None of the included files below include this file.#include "ScreenRepository.h"#include "Globals.h"#include "Subsystem.h"#include "Process.h"#include "ResourceManager.h"#include "ProcessManager.h"#include "DevConsole.h"#include "Aspect.h"#include "KeyboardInterpreter.h"#include "Screen.h"#include "EvKeyDown.h"#include "EvKeyUp.h"#include "EvChar.h"#include "EvMouseDown.h"#include "EvMouseUp.h"#include "EvSceneBegins.h"class HumanGameView : public Subsystem, public Process{        ...        // This is the offending line for the first error in the OP.	shared_ptr<ScreenRepository> mScreenRepository;        ...};

// LogicLayer.h// None of these files include HumanGameView.h. The only one that// includes ScreenRepository.h is HumanGameView.h, above.#include "Subsystem.h"#include "ProcessManager.h"#include "ResourceManager.h"#include "HumanGameView.h"#include "EntityManager.h"#include "PhysicsSystem.h"#include "SceneMainMenu.h"#include "InitOptions.h"#include "EvTick.h"class LogicLayer : public Subsystem{        ...        // This line causes the second error.	shared_ptr<HumanGameView> mHumanGameView;        ...};

A mess, I know! Thanks for the responses and kind words. :)

##### Share on other sites
We need to see the cpp files.

##### Share on other sites
Problem solving technique 1: run the offending source file through the preprocessor (for MSVC you can use the /P switch). Search the resulting file for the first usage of "HumanGameView" and "ScreenRepository". See what they are.

Problem solving technique 2: make a copy of your project (source control helps). Delete lines from your source code and compile every so often. Once the error stops occuring, then it's probable that something you just deleted contributes to the problem. Examine those lines. If you can determine the problem just from that, then everything is golden. If not, start deleting other lines until you can't delete anything without either figuring out the problem or removing the problem. If you've deleted everything you could without figuring out the problem, then post the resulting code here. That should be a minimal but complete example of the issue.

##### Share on other sites
Are you using namespaces? Do you use "using ..." somewhere?

##### Share on other sites
Have you tried just compiling those single source files rather then the whole build?

##### Share on other sites
You're being reluctant to post the relevant code, so it's very hard to guess. By omitting the things that *you* think are irrelevant, your probably omitting the code that is the cause of the problem.

So my complete-and-utter guess is that you have left header-guards unchanged when copying/pasting code in to a new header file.

[Edited by - the_edd on February 9, 2008 8:07:39 PM]

##### Share on other sites
Quote:
 Original post by SiCraneProblem solving technique 1: run the offending source file through the preprocessor (for MSVC you can use the /P switch). Search the resulting file for the first usage of "HumanGameView" and "ScreenRepository". See what they are.

It creates a bunch of different files, one for each translation unit. Is that what you mean? What would count as the first usage?

Quote:
 Original post by SiCraneProblem solving technique 2: make a copy of your project (source control helps). Delete lines from your source code and compile every so often....

I might have to do this eventually. :/ There's thousands of lines of code, though; I was hoping there was some category of problem that creates exactly this error pattern.

Quote:
 Original post by yaustarHave you tried just compiling those single source files rather then the whole build?

Yeah, same problem, but thanks for the response.

Quote:
 Original post by AntheusAre you using namespaces? Do you use "using ..." somewhere?

The only using's I have are for std and boost -- none of my own. Could that cause a problem like this?

Quote:
 Original post by the_eddYou're being reluctant to post the relevant code, so it's very hard to guess. By omitting the things that *you* think are irrelevant, your probably omitting the code that is the cause of the problem.

Sorry -- I'll post some code! I have dozens of classes though. I'll post the ones that were being changed sometime before the problem cropped up.

// HumanGameView.cpp#include "HumanGameView.h"HumanGameView::HumanGameView(int clientWidth, int clientHeight) : Process(),	mClientWidth(clientWidth), mClientHeight(clientHeight), TOGGLE_DC_CHAR('~'){	HR(D3DXCreateSprite(gDevice, &mSprite));	//mDevConsole.reset(new DevConsole(mSprite));	mScreenRepository.reset(new ScreenRepository(mSprite, mClientWidth, mClientHeight));}HumanGameView::~HumanGameView(){	RELEASECOM(mSprite);}bool HumanGameView::init(){	std::vector<int> desiredEvents;	desiredEvents.push_back(EV_DEVICE_LOST);	desiredEvents.push_back(EV_DEVICE_RESET);	desiredEvents.push_back(EV_RENDER);	desiredEvents.push_back(EV_KEY_DOWN);	desiredEvents.push_back(EV_KEY_UP);	desiredEvents.push_back(EV_CHAR);	desiredEvents.push_back(EV_MOUSE_DOWN);	desiredEvents.push_back(EV_MOUSE_UP);	desiredEvents.push_back(EV_SCENE_BEGINS);	registerForEvents(desiredEvents);	// Create our ProcessManager.	mProcessMan.reset(new ProcessManager());	// Create our KeyboardInterpreter and add it to the ProcessManager.	shared_ptr<KeyboardInterpreter> keyboardInterpreter(new KeyboardInterpreter());	if (!keyboardInterpreter->init())		return false;	mProcessMan->addProcess(keyboardInterpreter);	return true;}bool HumanGameView::update(float dt){	mProcessMan->updateProcesses(dt);	return false;}// Return value indicates whether the event was consumed and should cease to be propagated by the// event manager.bool HumanGameView::handleEvent(shared_ptr<Event> event){	switch (event->getType())	{	case EV_CHAR:		{			shared_ptr<EvChar> evChar = dynamic_pointer_cast<EvChar>(event);			TCHAR ch = (TCHAR)evChar->getWParam();			// this is correct, uncomment when methods are implemented			/*if (ch == TOGGLE_DC_CHAR)				mDevConsole->toggleVisible();			else				mDevConsole->acceptCharacter(ch);*/			return true;		}	case EV_MOUSE_DOWN:		{			shared_ptr<EvMouseDown> mouseDown = dynamic_pointer_cast<EvMouseDown>(event);			POINT screenCoords = mouseDown->getCoords();			mCurScreen->checkMouseDown(mouseDown->getMouseButton(), screenCoords);			return true;		}	case EV_MOUSE_UP:		{			shared_ptr<EvMouseUp> mouseUp = dynamic_pointer_cast<EvMouseUp>(event);			POINT screenCoords = mouseUp->getCoords();			mCurScreen->checkMouseUp(mouseUp->getMouseButton(), screenCoords);			return true;		}	case EV_SCENE_BEGINS:		{			shared_ptr<EvSceneBegins> sceneBegins = dynamic_pointer_cast<EvSceneBegins>(event);			handleEvSceneBegins(sceneBegins->getSceneType());		}	default:		return false;	}}// Return value indicates whether the event was consumed and should cease to be propagated by the// event manager.bool HumanGameView::handleEvent(int eventType){	switch (eventType)	{	case EV_RENDER:		render();		return true;	case EV_DEVICE_LOST:		// Fonts and anything in D3DPOOL_DEFAULT must have OnLostDevice and OnResetDevice called.		// This debug message didn't trigger in windowed mode. Next time fullscreen is run, these		// events should be checked to make sure the HGV is indeed getting them.		//MessageBox(0, _T("HGV says device was lost"), 0, MB_OK);		mSprite->OnLostDevice();		return false;	case EV_DEVICE_RESET:		//MessageBox(0, _T("HGV says device was reset"), 0, MB_OK);		mSprite->OnResetDevice();		return false;	default:		return false;	}}bool HumanGameView::handleEvSceneBegins(int sceneType){	switch (sceneType)	{	case SCENE_MAIN_MENU:		//temp!		//mCurScreen = mScreenRepository->getMainMenuScreen();		mCurScreen = mScreenRepository->getTestScreen();		break;	}	return false;}void HumanGameView::render(){	// Clear the back buffer and depth buffer, and send the start signals.	HR(gDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 0, 255), 1.0f, 0));	HR(gDevice->BeginScene());	HR(mSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT));	HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true));	// Draw everything that needs to be drawn.	mCurScreen->draw(0, 0);	// The DevConsole, because of its backdoor nature, is always drawn.	//mDevConsole->draw();	// End the scene.	HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false));	HR(mSprite->End());			// Sprites are flushed here	HR(gDevice->EndScene());	// Present the back buffer.	HR(gDevice->Present(0, 0, 0, 0));}

// HumanGameView.h#ifndef HUMANGAMEVIEW_H#define HUMANGAMEVIEW_H#include <map>#include "ScreenRepository.h"#include "Globals.h"#include "Subsystem.h"#include "Process.h"#include "ResourceManager.h"#include "ProcessManager.h"#include "DevConsole.h"#include "Aspect.h"#include "KeyboardInterpreter.h"#include "Screen.h"#include "EvKeyDown.h"#include "EvKeyUp.h"#include "EvChar.h"#include "EvMouseDown.h"#include "EvMouseUp.h"#include "EvSceneBegins.h"class HumanGameView : public Subsystem, public Process{public:	HumanGameView(int clientWidth, int clientHeight);	~HumanGameView();	bool init();	bool update(float dt);private:	bool handleEvent(shared_ptr<Event> event);	bool handleEvent(int eventType);	bool handleEvSceneBegins(int sceneType);	void render();	// This class is responsible for filling and deleting this naked pointer.	ID3DXSprite* mSprite;	// The character that toggles DevConsole visibility.	const TCHAR TOGGLE_DC_CHAR;;	//shared_ptr<DevConsole> mDevConsole;	shared_ptr<ScreenRepository> mScreenRepository;	shared_ptr<ProcessManager> mProcessMan;	// The screen that is currently active and being displayed.	shared_ptr<Screen> mCurScreen;	// Passed down from AppLayer through LogicLayer.	int mClientWidth, mClientHeight;};#endif

1. 1
2. 2
JoeJ
20
3. 3
frob
19
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632204
• Total Posts
3004764

×