Skip to main content
gamedev.net
🔒 Locked

Ghost Code Block

Started by dvak Nov 16, 2008 at 8:23 PM 11 replies 1.9k views
Original Post
dvak
dvak
hiyaz, im getting an error with the offedning code: line 14 "HE_Graphics graphicsPtr;"
Quote:
error C2146: syntax error : missing ';' before identifier 'graphicsPtr'
Without the line of code it compiles fine. Here's what ive tried so far: 0.Moving the line of code later in the class (still causes error just differnt line number 1.replaceing the HE_Graphics with Other Classes. same error 2.Searched up and down formissing ";" in included classes 3.getting rid of the class all together, this causes a similar error in a different class 4.deleting *.ncb 5.reInstalling vc++ 6.Recreating all classes 7.Deleting similar or Duplicate classes Heres the code for the Class currently giving me the prob.

#pragma once
#include "stdafx.h"
#include "HE_Object.h" // dont really need this here, just so i know what im using


class HE_SceneGraph
{
public:
	
	HE_SceneGraph(void);
	~HE_SceneGraph(void);
	
	
	HE_Graphics graphicsPtr; // <-------- OFFENDING LINE
	HE_Object world;	
	std::vector<HE_Object*> list;	
	
	void add(HE_Object &item);	
	void remove(void);	
	void print(void);	
	
};



vcpp 2008 compiler intel mac - Booting into XP sp1
TacticalPenguin
TacticalPenguin
Sorry for not having a clue as the syntax looks fine to me, but I just have a question. What is this:
	HE_SceneGraph(void);	~HE_SceneGraph(void);

for? The only use I've ever seen of ~ before is as the bitwise operator. Maybe I am just misunderstanding the code's structure and setup.
Alatar
Alatar
Have you checked the include files for missing ;'s?

@TacticalPenguin - The ~ means that it is a destructor for the class.

Edit - sorry, i just reread your post, and you already tried what I suggested. Sorry again.
"All you have to decide is what to do with the time that is given to you." - Gandalf
RDragon1
RDragon1
Did you include the header file that HE_Graphics is defined in? I only see #include "HE_Object.h"
dvak
dvak
One of the headers has a huge list of other classes that the problem ";" could be in. I get a similar problem in another class if I leave out the sceneGraph class. So instead of manually searching through 20 different classes, that seem to compile fine on their own, is there another way to find a missing ";"??
Ive gone over HE_Graphics a million times already which tells me it's a different class.

dvak
dvak
im assuming theres no headers being used within the class with this code, yet im getting the same errors:

#pragma once//#include "stdafx.h"//#include "HE_Object.h"//#include "HE_Graphics.h"//#include <vector>class HE_SceneGraph{public:		HE_SceneGraph(void);	~HE_SceneGraph(void);			HE_Graphics graphicsPtr;	//HE_Object world;		//std::vector<HE_Object*> list;			//void add(HE_Object &item);		void remove(void);		void print(void);			};


is it possible that the problem could be a different Class Calling HE_SceneGraph class???

[Edited by - dvak on November 17, 2008 1:57:33 AM]
dvak
dvak
OK...Perhaps this means something more. Here is a new error with a basically blank class:

Quote:

he_scenegraph.h(9) : error C2011: 'HE_SceneGraph' : 'class' type redefinition


//#pragma once//#include "stdafx.h"//#include "HE_Object.h"//#include "HE_Graphics.h"//#include <vector>class HE_SceneGraph{public:		HE_SceneGraph(void);	~HE_SceneGraph(void);			//HE_Graphics *graphicsPtr;	//HE_Object world;		//std::vector<HE_Object*> list;			//void add(HE_Object &item);		//void remove(void);		//void print(void);			};


As said before i've deleted the *.ncb file, and there is no similar class in my project folder. Any other ideas??
MortusMaximus
MortusMaximus
Quote:
Original post by dvak
OK...Perhaps this means something more. Here is a new error with a basically blank class:

Quote:

he_scenegraph.h(9) : error C2011: 'HE_SceneGraph' : 'class' type redefinition


*** Source Snippet Removed ***

As said before i've deleted the *.ncb file, and there is no similar class in my project folder. Any other ideas??


It looks here like you are including the file in multiple places. Uncommenting #pragma once should fix this.

It looks to me like the problem with the code in your original post is in the HE_Graphics class. This error when there is obviously a semi-colon usually means that the type of object you are trying to declare is not a valid type. Doing a forward declaration should fix the error.

This is a forward declaration:
class HE_Graphics;

A forward declaration won't make the actual declaration come up as an error when it gets to it; it just tells the compiler that you intend to define this class later on.
Check out the first gameplay video from my javascript/PHP RTS game
dvak
dvak
the forward declaration worked! genious. THANK YOU!!
why is it that including the "Graphics" class in the header doesn't do the same thing.??
MortusMaximus
MortusMaximus
Quote:
Original post by dvak
the forward declaration worked! genious. THANK YOU!!
why is it that including the "Graphics" class in the header doesn't do the same thing.??


It's impossible to tell without seeing all of your code, unfortunately. Also, I am not very familiar with the msvs compiler/linker, so I might not be able to tell you even if you showed me the code. I just recognize that particular error, as I have run into it myself many times before. When I first started C++, I never thought to come to one of these websites to ask questions, so I would spend many many hours figuring them out... but by golly, I never forgot the solutions ;)
Check out the first gameplay video from my javascript/PHP RTS game
Zipster
Zipster
A few common things to check for:

1) Circular includes. They usually manifest themselves as weird type errors.

2) Circular dependencies, which usually lead to circular includes.

2) Pointers versus instances. 'HE_Graphics graphicsPtr' declares an instance of HE_Graphics, whereas 'HE_Graphics* graphicsPtr' declares a pointer to an instance of HE_Graphics. You seem to have gone back and forth in the code you posted, so while the variable name indicated a pointer it's unclear what you were actually compiling. With a pointer, you should almost always be forward-declaring. Instances require the header file to be included. If including the header didn't work, then check for something like a missing semi-colon after the class definition.

3) Missing header guards or '#pragma once'.

Without seeing all the code it's hard to know exactly why the original code didn't compile.
dvak
dvak
Thats great. Thanks a lot friends!
swiftcoder
swiftcoder
You also might want to note that you don't need to a function as taking void as its argument in C++. A function declaration with an empty argument list is equivalent to a C function taking a single void argument, and the later is not often used in C++.
// prefervoid MyCPPFunc();// overvoid MyCFunc(void);
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.