Hello,
I have some issue with drawing vectror of class containing shape objects.
Below sample code:
#include <SFML/Graphics.hpp>
#include <iostream>
class Block
{
private:
sf::RectangleShape rectangle;
public:
sf::RectangleShape create ( int xPos, int yPos );
};
sf::RectangleShape Block::create ( int xPos, int yPos )
{
sf::RectangleShape object( sf::Vector2f ( 120, 50 ) );
object.setPosition( xPos, yPos );
return object;
}
int main()
{
sf::RenderWindow window;
window.create(sf::VideoMode(800, 600), "Sample application");
std::vector < Block > blocks;
Block *ptr;
for (int i = 0; i < 10; i++)
{
ptr = new Block;
ptr->create( i*2, i*2 );
blocks.push_back(*ptr);
}
delete ptr;
ptr = NULL;
//Windows
while(window.isOpen())
{
//Event Handler
sf::Event event;
while(window.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
window.close();
}//if
}//while
window.clear();
for ( int i = 0; i < blocks.size(); i++ ) {
window.draw( blocks[i] ); /** ERROR */
}
window.display();
}//while
}//main
Qustion is why am I getting an error?
In advance, thank You for answer