Jump to content
  • Advertisement
Sign in to follow this  
sakatius

variable or field centerSprite' declared void

This topic is 3771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!