[SFML] sf::Image w argumencie klasy - problem
Ostatnio zmodyfikowano 2013-04-28 17:06
sinoo Temat założony przez niniejszego użytkownika |
[SFML] sf::Image w argumencie klasy - problem » 2013-04-28 16:54:43 Witam, mam pewien problem z kompilacją kodu, a konkretnie kompilator wyrzuca błąd dotyczący 4 argumentu klasy, którym jest sf::Image. Oto kod: #include <SFML\Graphics.hpp> #include <vector>
class Obiekt { protected: int xPosition; int yPosition; int ID; sf::Sprite Sprajt; public: Obiekt( int id, int xPos, int yPos, sf::Image * img ) : xPosition( xPos ) , yPosition( yPos ) { Sprajt.SetImage( img ); } bool Colision( int ID ) { } };
class Hero : public Obiekt { public: Hero( int id, int xPos, int yPos, sf::Image * img ) : Obiekt( id, xPos, yPos, img ) { } void GoLeft() { } void GoRight() { } void GoUp() { } void GoDown() { } };
int main() { sf::RenderWindow AppWin( sf::VideoMode( 800, 600, 32 ), "Game window title" ); sf::Image blok1; sf::Image heroIMG; blok1.LoadFromFile( "blok1.jpg" ); heroIMG.LoadFromFile( "hero.png" ); std::vector < Obiekt > vObiekty; while( AppWin.IsOpened() ) { Hero hero( 0, 100, 200, heroIMG ); sf::Event Event; while( AppWin.GetEvent( Event ) ) { if( Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::W ) hero.GoUp(); if( Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::S ) hero.GoDown(); if( Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::A ) hero.GoLeft(); if( Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::D ) hero.GoRight(); if( Event.Type == sf::Event::Closed ) AppWin.Close(); } AppWin.Clear(); AppWin.Display(); } } A to log z kompilacji: 1>------ Build started: Project: SFML_Game, Configuration: Debug Win32 ------ 1>Compiling... 1>main.cpp 1>c:\documents and settings\user\moje dokumenty\visual studio 2008\projects\sfml_game\sfml_game\main.cpp(16) : error C2664: 'sf::Sprite::SetImage' : cannot convert parameter 1 from 'sf::Image *' to 'const sf::Image &' 1> Reason: cannot convert from 'sf::Image *' to 'const sf::Image' 1> No constructor could take the source type, or constructor overload resolution was ambiguous 1>c:\documents and settings\user\moje dokumenty\visual studio 2008\projects\sfml_game\sfml_game\main.cpp(56) : error C2664: 'Hero::Hero(int,int,int,sf::Image *)' : cannot convert parameter 4 from 'sf::Image' to 'sf::Image *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1>Build log was saved at "file://c:\Documents and Settings\User\Moje dokumenty\Visual Studio 2008\Projects\SFML_Game\SFML_Game\Debug\BuildLog.htm" 1>SFML_Game - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
|
pekfos |
» 2013-04-28 17:03:33 Problem nie dotyczy SFMLa, tylko podstaw C++: Poczytaj, czym różni się referencja od wskaźnika. |
|
sinoo Temat założony przez niniejszego użytkownika |
» 2013-04-28 17:06:43 sorki za nieogarnięcie i dzięki ;) Temat zamykam. |
|
« 1 » |