Nie znaleziono funkcji.

0

Podczas kompilacji wyskakuje mi błąd nie zdeklarowano funkcji o nazwie "moove", "ptexture" i "Event" uczę się dopiero programowania obiektowego więc nie za bardzo wiem o co chodzi z tymi błędami.

Kod:
Base.h

#include <SFML/Graphics.hpp>
#include "player.h"
#include "variable.h"

class Base
{
public:
	Base();
	~Base();

	void start();

private:
	void draw();

	sf::RenderWindow window;

	Player player;
}; 

Base.cpp

#include "base.h"

Base::Base()
{
	window.create(sf::VideoMode(window_w,window_h),"");

    ptexture.loadFromFile("data/player.png");
    player.setPosition(200,300);
    player.setTexture(ptexture);
}


Base::~Base()
{

}

void Base::start()
{
	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
            if (event.type == Event::KeyReleased)
			{
                if (event.key.code == sf::eyboard::Left)
                {
                    moove(-1, 0);
                }
				else if (event.key.code == sf::Keyboard::Right)
				{
					moove(1, 0);
				}
				else if (event.key.code == sf::Keyboard::Up)
				{
					moove(0, -1);
				}
				else if (event.key.code == sf::Keyboard::Down)
				{
					moove(0, 1);
				}
			}
		}

		draw();
	}
}

void Base::draw()
{
	window.clear(sf::Color(R,G,B));
    player.draw(window);
	window.display();
} 

Player.h

#include <SFML/Graphics.hpp>

class Player
{
public:
    Player();
    ~Player();

    void moove(float,float);
    void setPosition(int,int);
    void setTexture(sf::Texture &);
	void draw(sf::RenderWindow &);

	float x();
	float y();

private:
    int hp;
	int strength;
    float speed;

	sf::Texture *ptexture;
	sf::Sprite player;
}; 
#include "player.h"

Player::Player()
{
    hp = 100;
	strength = 5;
    speed = 250;

    ptexture = NULL;
}

Player::~Player()
{

}

Player::moove(float x, float y)
{

}

Player::setPosition(int x, int y)
{

}

Player::setTexture(sf::Texture &t)
{
	ptexture = &t;
	player.setTexture(*texture);
}

Player::draw()
{

}

float Player::x()
{
	return player.getPosition().x;
}

float Player::y()
{
	return player.getPosition().y;
} 
1

Nie bardzo rozumiem pytanie. Przecież klasa Base nie ma takiej metody więc czemu się dziwisz że nie moze jej wywołać? Może chciałeś przesunąć gracza czyli zrobić player.moove(...)? Pomyśl trochę! A co jakbyś w basie miał dwóch graczy? To jaki byłby efekt wywołania moove gdyby sie je dało wywołać tak jak chciałeś to zrobić? o_O

0

Ok. Dzięki za podpowiedź naprawiłem wszystko co wcześniej wyskakiwało a teraz mi to wyskakuje:

player.cpp|17|error: ISO C++ forbids declaration of 'moove' with no type [-fpermissive]|
player.cpp|17|error: prototype for 'int Player::moove(float, float)' does not match any in class 'Player'|
player.h|9|error: candidate is: void Player::moove(float, float)|
player.cpp|22|error: ISO C++ forbids declaration of 'setPosition' with no type [-fpermissive]|
player.cpp|22|error: prototype for 'int Player::setPosition(int, int)' does not match any in class 'Player'|
player.h|10|error: candidate is: void Player::setPosition(int, int)|
player.cpp|27|error: ISO C++ forbids declaration of 'setTexture' with no type [-fpermissive]|
player.cpp|27|error: prototype for 'int Player::setTexture(sf::Texture&)' does not match any in class 'Player'|
player.h|11|error: candidate is: void Player::setTexture(sf::Texture&)|
player.cpp|33|error: ISO C++ forbids declaration of 'draw' with no type [-fpermissive]|
player.cpp|33|error: prototype for 'int Player::draw(sf::RenderWindow&)' does not match any in class 'Player'|
player.h|12|error: candidate is: void Player::draw(sf::RenderWindow&)|
0

No dlaczego te Twoje funkcje nie mają typu zwracanego? Przecież dokładnie o tym jest napisane w komunikacie błędu. Przeczytaj jakiś tutorial / książkę (o C++) najpierw, a potem pisz klasy.

0

Może i mam drobny problem ze wzrokiem ale tego

uczę się dopiero programowania obiektowego
NIE POWINNO dać się przegapić!

0

Nawet jak nic z metody nie zwracasz, czyli typ zwracany jest void, musisz to napisać w pliku cpp też.

Player::moove(float x, float y)
{
 
}

na

void Player::moove(float x, float y)
{
 
}

i z resztą takich metod też

1 użytkowników online, w tym zalogowanych: 0, gości: 1