I'm kinda new to C++ but I love how easy it was for me to get a simple sprite setup and moving with SFML. Now I'm trying to refactor my code so that I take everything related to "player" outside of the int main call and put it in its own class.
So I wrote out my header file and started to write the actual .cpp file when I ran into errors compiling. I don't know what I'm doing wrong.
If anyone would be kind enough to help me or point me the direction of help that would be great.
I have included the header, cpp, and compile log below.
BTW: I'm using SFML-1.4, CodeBlocks with MinGW. I'm also compiling on Windows.
#ifndef PLAYER_H
#define PLAYER_h
#include <string>
#include <SFML/Graphics.hpp>
class Player
{
private:
std::string name;
sf::RenderWindow window;
sf::Vector2 position;
bool isWalking;
public:
Player(std::string name, sf::Vector2 position, sf::RenderWindow window);
~Actor();
void update();
void draw();
std::string getName();
sf::Vector2 getPosition();
};
#endif
#include "Player.h"
Player::Player(std::string name, sf::Vector2 position, sf::RenderWindow *window)
: name(name), position(position), window(window)
{
}
Player::~Player()
{
}
void Player::update()
{
}
void Player::draw()
{
}
std::string Player::getName()
{
return name;
}
sf::Vector2 Player::getPosition()
{
return position;
}
-------------- Build: Debug in Client ---------------
Compiling: src\main.cpp
Compiling: src\Player.cpp
In file included from C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:1:
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:13: error: using-declaration for non-member at class scope
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:13: error: expected `;' before "position"
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:17: error: `sf::Vector2' is not a type
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:17: error: ISO C++ forbids declaration of `position' with no type
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:18: error: expected class-name before '(' token
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:24: error: using-declaration for non-member at class scope
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:24: error: expected `;' before "getPosition"
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:3: error: `sf::Vector2' is not a type
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:4: error: ISO C++ forbids declaration of `position' with no type
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:4: error: prototype for `Player::Player(std::string, int, sf::RenderWindow*)' does not match any in class `Player'
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:9: error: candidates are: Player::Player(const Player&)
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.h:17: error: Player::Player(std::string, int, sf::RenderWindow)
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp: In constructor `Player::Player(std::string, int, sf::RenderWindow*)':
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:4: error: class `Player' does not have any field named `position'
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp: At global scope:
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:10: error: definition of implicitly-declared `Player::~Player()'
C:\Documents and Settings\Dro\Desktop\GunKnights\client_code\src\Player.cpp:29: error: expected constructor, destructor, or type conversion before "Player"
Process terminated with status 1 (0 minutes, 1 seconds)
15 errors, 0 warnings
Again, thanks in advance to anyone who could help me.