I am currently trying to learn more about object oriented design in C ++ (familiar with Java) and I am running into some walls. The project I'm trying to put together to learn these principles in a game built using SFML for graphics and sound. I have the following two files.
WorldObject.h
#ifndef WORLDOBJECT_H #define WORLDOBJECT_H #include <SFML/Graphics.hpp> #include <string> #include "ImageManager.h" class WorldObject { private: sf::Sprite _sprite; void SetImagePath(std::string path); sf::Sprite GetGraphic(); }; #endif
WorldObject.cpp
#include "WorldObject.h" void WorldObject::SetImagePath(std::string path) { _sprite.SetImage(*gImageManager.getResource(path)); } sf::Sprite GetGraphic() { return _sprite; }
I do not see any problems with them, but when I try to compile them, I get the following error from g ++:
WorldObject.cpp: In function 'sf::Sprite GetGraphic()': WorldObject.cpp:9: error: '_sprite' was not declared in this scope make: *** [WorldObject.o] Error 1
What am I missing in this code? Trying to figure out the right way to set up the inheritance hierarchy has caused most problems so far in game development, but I know that this is primarily due to the fact that I am more likely to use the Java inheritance model rather than the C ++ multiple inheritance model.
source share