fork download
  1. #include <SFML/Graphics.hpp>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;using namespace sf;
  5.  
  6. class Obj
  7. {
  8. public:
  9. Obj(int x, int y, string path) : _x(x), _y(y), _path(path)
  10. {
  11. texture.loadFromFile(path);
  12. sprite.setTexture(texture);
  13. }
  14. void create()
  15. {
  16. texture.loadFromFile(path);
  17. sprite.setTexture(texture);
  18. }
  19.  
  20. int _x;
  21. int _y;
  22. string path;
  23. Sprite sprite;
  24. Texture texture;
  25. };
  26.  
  27. int main()
  28. {
  29. //Вот так рисуется:
  30. std::vector<Obj> obj;
  31. obj.emplace_back(16, 16, "res/sprite.png");
  32.  
  33. //Но если 2строки выше заменить этим:
  34. std::vector<Obj> obj;
  35. Obj.reserve(1);
  36. Obj[0].x = 16;
  37. Obj[0].y = 16;
  38. Obj[0].path = "res/sprite.png";
  39. Obj[0].create();
  40.  
  41. window()
  42. {
  43. while (window.isOpen())
  44. {
  45. window.draw(Obj[0].sprite); //эта строка начнет крашить приложение
  46. }
  47. }
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:29: fatal error: SFML/Graphics.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty