variable or field centerSprite' declared void

Started by
0 comments, last by Zakwayda 16 years, 1 month ago
I can't figure what in the world is going on, this is my DivContainer.h file:

#ifndef DIV_CONTAINER_H
#define DIV_CONTAINER_H

#include "Coor.h"

class DivContainer{

    public:
        Coor position;
        int width, height; // The width and height of the DivContainer
        
        // Constructors
        DivContainer(){}
        DivContainer(Coor pos, int w, int h);
        
        // Methods
        void centerSprite(Sprite &s);
        void draw(SDL_Surface*& screen);
        Coor getCenterCoor(SDL_Surface *g);
        
        // Accessor functions
        int getWidth() const{ return width; }
        int getHeight() const{ return height; }
        
        int getTopBoundary() const{ return position.y; }
        int getRightBoundary() const{ return position.x + width; }
        int getBottomBoundary() const{ return position.y + height; }
        int getLeftBoundary() const{ return position.y; }
        
    private:
};

#endif

My centerSprite is clearly meant to be a function, I don't understand why my compiler is confused. In addition, within my Sprite.h header for my Sprite class, the compiler doesn't recognize 'DivContainer' as a type, "'DivContainer' does not name a type". Sprite.h:

#ifndef SPRITE_H
#define SPRITE_H

#include <iostream>
#include <sstream>
#include <string>
#include "Coor.h"
#include "DivContainer.h"

class Sprite{

    public:
        Coor position;
        SDL_Surface *image;
        DivContainer bounds; // The bounding box of the sprite // ??? 'DivContainer' does not name a type" -- ???
        int width, height; // The width and height of the sprite's bounding box
        
        // Constructors
        Sprite();
        Sprite(Coor pos, string imagePath, bool transparent);
        Sprite(Coor pos, SDL_Surface*& image); // Deprecated.
        ~Sprite();
        
        // Accessor functions
        Coor getPosition();
        Coor getTopLeftCorner();
        Coor getBottomRightCorner();
        int getWidth() const{ return width; }
        int getHeight() const{ return height; }
        DivContainer getBounds(); // ??? // Not sure why "'DivContainer' does not name a type"
        
        // Assignment functions
        void setTopLeftCorner(Coor pos);
        void setBottomRightCorner(Coor pos);
        void setPosition(Coor pos);
        void setDimensions(int w, int h){ width = w; height = h; } // Not used.
        
        // Methods
        void draw(SDL_Surface*& screen);
        
    private:
};

#endif

This is really throwing me off, please help! Thanks!
Advertisement
Just guessing here, but it looks like Sprite isn't declared or defined anywhere in DivContainer.h. You might try a forward declaration, e.g.:
void centerSprite(class Sprite &s);
Just be sure to include Sprite.h in DivContainer.cpp.

This topic is closed to new replies.

Advertisement