# Can someone educate me on where the syntax error is in this code?

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

## Recommended Posts

#include "Unit.h"

class VisualRenderer
{
public:

VisualRenderer();
~VisualRenderer();

void trackSingleUnit(const Unit& cUnit);
};


The last line, with the trackSingleUnit function, is highlighted and the error in Dev-C++ is: 13 C:\Documents and Settings\manjun\My Documents\c++\opengl\VisualRenderer.h expected ,' or ...' before '&' token and 13 C:\Documents and Settings\manjun\My Documents\c++\opengl\VisualRenderer.h ISO C++ forbids declaration of `Unit' with no type

##### Share on other sites
It looks a lot like Unit isn't defined. Check for a circular inclusion and add a forward declaration.

##### Share on other sites
It seems you're right.

Although, Unit is defined, but the declaration for it is enclosed in:

#ifndef UNIT_H
#define UNIT_H

#endif

When I removed these three lines, the program worked perfectly.

##### Share on other sites
I found my problem.

It seems that I also used the same #ifndef guard from above around my VisualRenderer class--I forgot to change the copy-and-pasted #ifndef UNIT_H to #ifndef VISUALRENDERER_H.

Thanks so much for the help.

##### Share on other sites
If you're using Visual Studio, you can also use #pragma once. It makes things much clearer and you avoid problems like the one you just had. Copy-and-pasting for the lose. :)

Not sure whether that will work on other compilers, however.

##### Share on other sites
Quote:
 Original post by unholymightI found my problem.It seems that I also used the same #ifndef guard from above around my VisualRenderer class--I forgot to change the copy-and-pasted #ifndef UNIT_H to #ifndef VISUALRENDERER_H.
Been there, done exactly that! Very confusing the first time, but the good news is that once you've done it you'll solve it far quicker next time.
It's all part of the learning process...