compiler insaine?

Started by
7 comments, last by Zahlman 19 years, 4 months ago
im staring to think my compiler should start to seee a doctor any way heres the problem my compiler gives me this error 19 C:\Dev-Cpp\projects\Homeland\Object.h type specifier omitted for parameter `Sprite_Handler'


#ifndef OBJECT_H
#define OBJECT_H
#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <vector>
#include <stdlib.h>                                     // Include this to use system()
#include <iostream>										// Include our standard header
#include <string>										// Include this to use strings
#include <fstream>
#include <libiberty.h>
#include "Sprite_Handler.h"//but im including the type here and i know its spelled right

class Object
{
    public:
        int z;
        Object(int x , int y , const char* New_I , Sprite_Handler* Sprite_Handler1); //in this line
        SDL_Rect R_Object;
        SDL_Surface* I_Object;
};    

Object::Object(int x,int y,const char* New_I, Sprite_Handler* Sprite_Handler1)
{
    R_Object.x = x;
    R_Object.y = y;
    I_Object = SDL_LoadBMP(New_I);
    Sprite_Handler1->addsprite(this);
};
#endif



i dunno maybe i should see someone but it looks ok to me thanks[smile] [Edited by - raptorstrike on November 27, 2004 8:17:02 PM]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
Shouldn't you be using -> in Sprite_Handler1.addsprite(this); since Object::Object(....Sprite_Handler* Sprite_Handler1)
yeah i should and now its fixed but that wasnt the problem tahnks though[smile]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
show us Sprite_Handler.h
here it is

#ifndef SPRITE_HANDLER_H#define SPRITE_HANDLER_H#include "SDL.h"#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <vector>#include <stdlib.h>                                     // Include this to use system()#include <iostream>										// Include our standard header#include <string>										// Include this to use strings#include <fstream>#include <libiberty.h>#include "Object.h"using namespace std;class Sprite_Handler{    public:        Sprite_Handler() {};        void TempRectBlit(SDL_Surface* src,SDL_Surface* dst,SDL_Rect Parent_Rect);        void DrawSprites(SDL_Surface* dst);        vector<Object*> Sprites;        void addsprite(Object* n_object);        };#endif
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:Original post by raptorstrike
here it is
From your error I can tell that in your source file you are including Sprite_Handler.h. This file includes object.h the be able to refrence the Object class. But the object.h can't include the Sprite_Handler.h because that would include Object.h again! That is why you can't access Sprite_Handler in Object.h!

Since you are using pointers you can solve this problem by using forward declarations instead of

#include "object.h"
&
#include "sprite_handler.h"

in sprite_handler.h and object.h respectively. In object.h this would force you to move the implementation of your Object constructor to a cpp file.

here is your new object.h:

#ifndef OBJECT_H#define OBJECT_H#include "SDL.h"#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <vector>#include <stdlib.h>                                     // Include this to use system()#include <iostream>										// Include our standard header#include <string>										// Include this to use strings#include <fstream>#include <libiberty.h>//#include "Sprite_Handler.h"//but im including the type here and i know its spelled rightclass Sprite_Handler;class Object{    public:        int z;        Object(int x , int y , const char* New_I , Sprite_Handler* Sprite_Handler1); //in this line        SDL_Rect R_Object;        SDL_Surface* I_Object;};    #endif


this is your new Sprite_Handler.h:
#ifndef SPRITE_HANDLER_H#define SPRITE_HANDLER_H#include "SDL.h"#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <vector>#include <stdlib.h>                                     // Include this to use system()#include <iostream>										// Include our standard header#include <string>										// Include this to use strings#include <fstream>#include <libiberty.h>// not #include "Object.h"class Object;using namespace std;class Sprite_Handler{    public:        Sprite_Handler() {};        void TempRectBlit(SDL_Surface* src,SDL_Surface* dst,SDL_Rect Parent_Rect);        void DrawSprites(SDL_Surface* dst);        vector<Object*> Sprites;        void addsprite(Object* n_object);        };#endif
well i tried what you said but got a bunch of INVALID use of struct in my cpp files so using your same basic logic i moved the constructer to a diffrent source file and now it works
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:Original post by raptorstrike
well i tried what you said but got a bunch of INVALID use of struct in my cpp files so using your same basic logic i moved the constructer to a diffrent source file and now it works
I dont really know what you mean... I said you should move the constructor to a cpp file. The cpp file must include object.h?
<3

This topic is closed to new replies.

Advertisement