Sign in to follow this  

Ghost Code Block

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
the forward declaration worked! genious. THANK YOU!!
why is it that including the "Graphics" class in the header doesn't do the same thing.??

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++.
// prefer
void MyCPPFunc();
// over
void MyCFunc(void);

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this