Advertisement

a missing ; before defined object??? Plz help me out

Started by September 14, 2001 01:30 AM
7 comments, last by _Titan_ 23 years, 5 months ago
Before you ask how stupid am i, I''d jsut like to point out that i can not track down this problem because if it were a missing ; i would be able to find it and fix it! I call a header file, Engine_GlbInc.h, and the first line is this extern HDC hDc; Now, for two .cpp files that call it (note: there are like 8 files that call this header) but its only 2 files, they give my errors like this error C2146: syntax error : missing '';'' before identifier ''hDC'' WTF!?!??!?!?! There is no missing ; before the declaration! What am i not seeing? Just for refference, the .cpp files that give this error are Initialize (which hold the initGL function in all NeHe projects) and Draw.cpp (which holds the DrawGl function) S0, why would i get this error? I can call functions in other .cpp files that have the same header incluided and they work fine i get no errors when compiling. Whats going on?!
Hmmm... look into where HDC is defined. Also, make sure you''re matching up the correct capitalization of HDC (I''m assuming yours is just a typo in you last reference).

Every time the compiler messes up for me and I swear up and down that the computer is just plain wrong I end up finding the error was mine.
Advertisement
It seems that you need an include before including the Engine_GlbInc.h file.
The compiler is interpreting that HDC is a variable name and not the type you''d expect. Try including the windows.h before the Engine_GlbInc.h.

When programming for windows, it''s a good idea to include windows.h at the begining of ALL files .c

"If you''re gonna die, die with your boots on"
The windows.h WAS included before i called my Engine_GlbInc.h so thats not the problem. And its not the way i spelled HDC cause if i put a different declaration up there it will give me the same error, Example;

I had

extern cCharactor Charactor;

cCharactor is a class And it gave me the same error.

error C2146: syntax error : missing ';' before identifier 'Charactor'

and i get this error in every file!! Not just two. I think cause i call this variable in all those files...?

Forgot, i also get an error right after it,

fatal error C1004: unexpected end of file found

So i get the missing ; and the end of file...whats going on?



Edited by - _titan_ on September 14, 2001 12:14:27 PM
//Just a little tippo.....

//ccstuff.h
class CStuff
{
public:
void yada();
}; <- important.....

//main.cpp
#include (...)
#include "ccstuff.h"

//Define the new var like this
CStuff *test = NULL;
//or like this
CStuff test;

//Execute it like this
test = new CStuff;
test->yada();
//or like this
test.yada();


I have no idea why i wrote this!

Just be sure that you end your class definition with a ; ...
If you don't, you will get the error you pointed out...
At least i do!

Take Care!

- -- ---[XaOs]--- -- -

[ project fy ]

Edited by - xaos on September 14, 2001 6:16:33 PM
- -- ---[XaOs]--- -- -[ Project fy ||| CyberTux ]
quote:
Original post by _Titan_
The windows.h WAS included before i called my Engine_GlbInc.h so thats not the problem. And its not the way i spelled HDC cause if i put a different declaration up there it will give me the same error, Example;

I had

extern cCharactor Charactor;

cCharactor is a class And it gave me the same error.

error C2146: syntax error : missing '';'' before identifier ''Charactor''

and i get this error in every file!! Not just two. I think cause i call this variable in all those files...?

Forgot, i also get an error right after it,

fatal error C1004: unexpected end of file found

So i get the missing ; and the end of file...whats going on?



Edited by - _titan_ on September 14, 2001 12:14:27 PM



Ok, let''s start at the beginning, you do have an hDc variable declared in your main .cpp file, right? ( if it''s in a header, try moving it to your main .cpp file )...

Now, if that is OK, try this:

// .h filestruct winVar_tag{   HDC hdc;   ...}winVar, *lpwinVarextern winVar wv;// in your main .cppwinVar wv;// in another .cppwinVar wv; 


see if that works, if it doesn''t, there''s definitely something wrong as I do that all the time and it works fine for me.

Hope this help.


"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
[Cyberdrek | ]
Advertisement
just a shot in the dark, but i''m assuming you have and #ifndef around your header. make sure that after the #endif you have a newline otherwise the compiler might choke on it
quote:
Original post by XaOs
//Just a little tippo.....

//ccstuff.h
class CStuff
{
public:
void yada();
}; <- important.....

//main.cpp
#include (...)
#include "ccstuff.h"

//Define the new var like this
CStuff *test = NULL;
//or like this
CStuff test;

//Execute it like this
test = new CStuff;
test->yada();
//or like this
test.yada(); <-- this line here


I have no idea why i wrote this!

Just be sure that you end your class definition with a ; ...
If you don''t, you will get the error you pointed out...
At least i do!



The line that I''m pointing to won''t work since you declared your test object using the new pointer. You would need to declare it like so:

CStuff test;

or
CStuff test = New CStuff;
CStuff &test2 = test; // reference to a object of class CStuff

in order to be able to use the "." notation

Also, I''m sorry to contradict you but you don''t need the ; at the end of your class definition anymore. It''s just safe practice to put it there but it''s not mandatory and it won''t generate any errors if you don''t.




"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
[Cyberdrek | ]
Well, just to let you know, you all were wrong...at least for this dumb problem. Anyways, what it was was i had HDC and GLvoid, these were not known to the dumb header, so i added the windows.h and the gl.h..someone mentioned to add the windows.h file in all my code, so i did, anyways, it was having a problem with the GLvoid and the HDC so i added the headers and it works now. I dont know why it would give me such a dumb way off error, but it did. Now we know how to fix it :D

I thank everyone for replying to try and help me! Much much appriciated and for it we are all a little biut wiser

This topic is closed to new replies.

Advertisement