c++ compilation bug

Started by
9 comments, last by EvilNando 12 years, 11 months ago
Okay this thing is really starting to get into my nerves....

I have 2 classes

Application and ModuleVideo


my Application class contains an instance of the ModuleVideo, the thing is that sometimes at compile time my compiler tells me that ModuleVideo needs a reference which is strange as I have the proper #include "ModuleVideo.h" at the header of Aplication class

but heres the funny thing:

if I comment the class and recompile (gets me some more errors) and then I uncomment and try to recompile again EVERYTHING WORKS OK

why is this?
Advertisement
sounds like you have two problems then:
- a dependency problem, regarding compilation
- a syntax problem too

how do you compile ?
can you show the source files ?
Don't paraphrase the compiler's error message. Please copy and paste the exact error message.
Also, what compiler are you using?
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
vs2010

pretty simple stuff





#ifndef APPLICATION_H_
#define APPLICATION_H_

#include "Common.h"
#include "ModuleVideo.h"

class Application
{
public:
// stuff
ModuleVideo module_video;
// more stuff
}

#endif



#ifndef MODULE_VIDEO_H_
#define MODULE_VIDEO_H_

#include "Common.h"

// stuff

#endif




the error:



Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...
Error 1 error C2146: syntax error : missing ';' before identifier 'module_video' ....



if I comment the class and recompile (gets me some more errors) and then I uncomment and try to recompile again EVERYTHING WORKS OK




Try cleaning and rebuilding if that happens. See if if that helps.

Now you are not reproducing the full source. We are not psychic - we cannot divine problems in code we cannot see. Does Common.h include either Application.h or ModuleVideo.h, directly or indirectly? What does Common.h have in it?
Well what's in "//stuff" ? and in Common.h ?

A good thing in general is to reduce/simplify your *real* code, while still keeping the problem, and then show us the *whole* thing.

class Application
{
public:
ModuleVideo module_video;
} // <-- Missing semicolon?
I will be very impressed if the problem lies on the code Ive omitted honestly

theres no way it should affect the compilation behavior, but what do I know...


#include <SDL.h>

#include <stdio.h>
#include <stdarg.h>
#include <fstream>
#include <sstream>
#include <string>

#include "Application.h"

// APPLICATION ERROR CODES
#define ERR_CODE_NONE 0

#define ERR_CODE_SDL_EVENT 1
#define ERR_CODE_SDL_INIT 2

#define ERR_CODE_MODULE_VIDEO 3
#define ERR_CODE_MODULE_VIDEO_SHADERS 4

#define ERR_CODE_FILE_NOT_FOUND 5
#define ERR_CODE_EMPTY_FILE 6

#endif




#ifndef APPLICATION_H_
#define APPLICATION_H_

#include "Common.h"
#include "ModuleVideo.h"

class Application
{
public:
Application();
~Application();

void Init(void);
int Run(void);
void ProcessEvent(SDL_Event*);

static void ShowMessage(char* msg, ...);

private:

bool is_running;
SDL_Event sdl_event;
int error_code;

ModuleVideo module_video;

};

#endif // APPLICATION_H_





#ifndef MODULE_VIDEO_H_
#define MODULE_VIDEO_H_

#include "Common.h"
#include <GL/glew.h>


#define DEFAULT_WIDTH 800
#define DEFAULT_HEIGHT 600

class ModuleVideo
{

public:
ModuleVideo();
~ModuleVideo();

Uint32 Init(void);
Uint32 Init(Uint32, Uint32);

void StartRender(void);
void EndRender(void);

Uint32 CreateShaderProgram(GLint&, const char*, const char*);

private:

Uint32 LoadShaderFile(const char*, std::string&);

union
{
Uint32 width;
Uint32 height;

} resolution;

SDL_Surface* sdl_surface;

};

#endif

Is the first file Common.h ?
If so, it's include guard is broken. After fixing it, I can make the thing compile.
(by the way, why is it including Application.h ?)

Looks like you removed too much code again. It's nice to simplify, so that we don't have to read pages and pages of code, but you have to keep the problem present (just test the simplified version before posting it).
Sometimes this process of simplifying will allow you to find the problem yourself.

This topic is closed to new replies.

Advertisement