C++ passing variable by reference (SFML window) -
i have problem passing variable reference. try draw in sfml window in class won't draw. if uncomment commented lines works. doing wrong?
#pragma once #include "stdafx.h" #include <sfml/graphics.hpp> #include "ball.h" int _tmain(int argc, _tchar* argv[]) { sf::renderwindow window = sf::renderwindow( sf::videomode( 640, 480 ), "sfml window" ); ball my_ball = ball ( sf::vector2f( 320.0, 240.0 ) ); window.clear(); my_ball.draw(window); //sf::circleshape circle; //circle.setradius( 30 ); //circle.setposition( sf::vector2f( 320.0, 240.0 ) ); //window.draw( circle ); window.display(); while(window.isopen()) { sf::event event; while( window.pollevent(event) ){ if( event.type == sf::event::closed ){ window.close(); } } sf::sleep( sf::milliseconds( 20 ) ); } return 0; } ball.h
#include <sfml/graphics.hpp> class ball { public: ball( sf::vector2f position, float size = 30.0 ); void draw( sf::renderwindow & window ) const; private: sf::vector2f position; float size; }; ball.cpp
#include "stdafx.h" #include "ball.h" ball::ball( sf::vector2f position, float size ) { position = position; size = size; } void ball::draw( sf::renderwindow & window ) const { sf::circleshape circle; circle.setradius( size ); circle.setposition( position ); window.draw( circle ); }
why assigning themselves? that's wrong
ball::ball( sf::vector2f position, float size ) { position = position; size = size; }
Comments
Post a Comment