I just recently got back into coding c++ after about a year's hiatus, so this may well be a basic mistake. I decided to drop SDL and I am starting to learn SFML. I created a basic Pong game, but when I tried to implement classes it didn't work. I tried to simplify the problem by just getting a class to represent an image, however I keep raising an error. I've torn my hair out trying to fix this, but I think I've reached a point where even if the solution was at first obvious, I will not find it. The program only encompasses 3 files.
main.cpp#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <windows.h>
#include "ball.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
sf::RenderWindow window(sf::VideoMode(200, 300), "Test");
Ball ball;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(ball.get_Sprite());
window.display();
}
return 0;
}
ball.h#ifndef BALL_H
#define BALL_H
#include "SFML\Graphics.hpp"
class Ball
{
private:
sf::Texture texture;
sf::Sprite sprite;
public:
Ball();
sf::Sprite get_Sprite();
};
#endif
ball.cpp#include "ball.h"
#include "SFML\Graphics.hpp"
Ball::Ball()
{
texture.loadFromFile("ball_img.png");
sprite.setTexture(texture);
}
sf::Sprite get_Sprite()
{
return sprite;
}
The error returned is
ball.cpp(12): error C2065: 'sprite' : undeclared identifier. Thank you.