Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / General Programming / C++ problem: weird includes Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

April 26, 2005, 04:26 AM

I've got a weird problem using Visual C++ (Microsoft Visual Studio .net 2003).
I don't know what I'm doing wrong. I've got the following:

#ifndef __Library_OpenGL_cDrawObject_hpp__
#define __Library_OpenGL_cDrawObject_hpp__

/* Gl includes */

/* Library includes */
// #include
// #include
// #include


which compiles nicely and runs ok.

But when I uncomment one or more of the commented lines, I get a lot of errors. But the thing is, the includes I've done are also included in some other files which I also already use in the running program.

The errors I get:

WheelsOfViolence2LibraryDataContainerMapcMap.hpp(42): error C2143: syntax error : missing ';' before '*'

Microsoft Visual Studio .NET 2003Vc7includestdlib.h(256): error C2381: 'exit' : redefinition; __declspec(noreturn) differs

WheelsOfViolence2LibraryDataContainerMapcMap.hpp(42): error C2501: 'cMap::aoStaticObjects_pp' : missing storage-class or type specifiers

WheelsOfViolence2LibraryDataContainerMapcMap.hpp(42): error C2501: 'cMap::scObject' : missing storage-class or type specifiers

WheelsOfViolence2LibraryDataContainerCarcCar.cpp(125): error C2593: 'operator *' is ambiguous

And except the last error, all these errors lot's of times(which VS seems to do always... repeating one error many times).

Can someone please help me. I don't mind sending the code or something, but I don't have a FTP or something.


PS. If you need more info to know what the problem is about, please tell me. But maybe someone already recognizes the errors and a possible problem/error that causes them.


April 26, 2005, 05:03 AM

Maybe it's because I've done something like? :

file A:

#ifndef FILEA
#define FILEA



#ifndef FILEB
#define FILEB




April 26, 2005, 05:16 AM

try adding windows.h


April 26, 2005, 05:23 AM

That didn't work... I already had an #include in my main file. I also put it in the file that caused the errors. But now I tried to include an other file at the same place with a class cBullet in it. This class inherits from scWeapon. And scWeapon inherits from scObject. But now it says base class scObject is undefined, but there is an include including this class so I don't understand anything anymore of it.

Somehow I think there is something about C++ (and includes perhaps) that I don't know of and which I'm doing wrong.


PS. now I remember I had an error like this before I think in a previous project it was caused by something like:

class a inherited from b and had an attribute of class c.
class c had a attribute of class a
or something like this. Now this example is stupid i know.. but what I mean is that the compiler needs b and c for compiling a, but it needs a and b for compiling c. But both a and c can't be finished compiling without each other.

Can this be correct in some way? (Maybe in a differnt case I described, I only tried to make my thought a little bit more clear).

I also remember someone telling me that it could be fixed using extern?



April 26, 2005, 06:15 AM

Problem solved! :)

I did this:

file cMap:

file scObject
#include DrawObject

file DrawObject

I think i can call this a flaw in my design not? :) But what is a good idea to prevent mistakes like these? I mean... is for example 'extern' a good idea?

I also had the problem of redefinition of exit. I use stdlib.h and glut.h.
I've edited the VS stdlib.h:
#ifndef __glut_h__
visual studie decl. of exit
#end if

is there a better way of doing this?



April 26, 2005, 06:37 AM

Cyclic includes can usually be solved using forward declaration.

In file A:

  2. #include <fileb.h>
  4. class A
  5. {
  6.     // ... Use class B here
  7. };

In file B:
  2. class A
  4. class B
  5. {
  6.     // ... Use class A here, but only pointers!
  7. };

But you should really think about why this cyclic dependency exists. As you say, this may be a flaw in your design.


April 26, 2005, 10:50 AM

Yes now I remember! :) I made this mistake before. It's so logical, but I only have about 4 a 5 days to make a complete game for school, so I've got a little bit of stress and now I made that mistake again. (I don't really have the time to make a real design too).


This thread contains 7 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.