By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

Unknown errors in a SFML/C++ project (Visual Studio 2019 v.16.2):

P: 6
I'm recently learning to make a 2d game in SFML using a tutorial series on youtube by Suraj Sharma(currently video 57):

https://www.youtube.com/watch?v=kwd_AVCkvXE&list=PL6xSOsbVA1ebkU66okpi-KViAO8_9DJKg&index=57

After 10:14 into the video i receives a bunch of errors in the 'TileMap' class

Here's the code:

TileMap.h:

Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2. #ifndef TILE_MAP_HH
  3. #define TILE_MAP_HH
  4.  
  5. #include "Tile.h"
  6.  
  7. class TileMap
  8. {
  9. private:
  10.     float GridSizeF;
  11.     unsigned GridSizeU;
  12.     unsigned Layers;
  13.     sf::Vector2u MaxSize;
  14.     std::vector<std::vector<std::vector<Tile>>>Map;
  15. public:
  16.     TileMap();
  17.     virtual~TileMap();
  18.  
  19.     //Funcs
  20.     void Update();
  21.     void Render(sf::RenderTarget& target);
  22. };
  23. #endif // !TILE_MAP_HH
TileMap.cpp:

Expand|Select|Wrap|Line Numbers
  1.  #include "pch.h"
  2. #include "TileMap.h"
  3.  
  4. TileMap::TileMap()
  5. {
  6.     this->GridSizeF = 50.f;
  7.     this->GridSizeU = static_cast<unsigned>(this->GridSizeF);
  8.     this->MaxSize.x = 10;
  9.     this->MaxSize.y = 10;
  10.     this->Layers = 1;
  11.  
  12.     /*Both push_back and resize functions have E0135 error
  13.     which says:
  14.         class "std::vector<std::vector<std::vector<Tile, std::allocator<Tile>>,
  15.         std::allocator<std::vector<Tile, std::allocator<Tile>>>>,
  16.         std::allocator<std::vector<std::vector<Tile, std::allocator<Tile>>,
  17.         std::allocator<std::vector<Tile, std::allocator<Tile>>>>>>"
  18.         has no member "push_back"("resize")
  19.         */
  20.     //E0020 : x,y,z are undefined
  21.     //E0065 : expected a ';' in x,y,z for loop declaration
  22.  
  23.     this->Map.resize(this->MaxSize.x);
  24.     for (size_t x = 0; x < this->MaxSize.x; x++)
  25.     {                
  26.         this->Map.push_back(std::vector<std::vector<Tile>>());
  27.         for (size_t y = 0; y < this->MaxSize.y; y++)
  28.         {    
  29.             this->Map.resize(this->MaxSize.x);
  30.             this->Map[x].push_back(std::vector<Tile>());
  31.             for (size_t z = 0; z < this->Layers; z++)
  32.             {    
  33.                 this->Map.resize(this->MaxSize.x);
  34.                 this->Map[x][y].push_back(Tile(x*this->GridSizeF, y * this->GridSizeF, this->GridSizeF));
  35.             }
  36.         }
  37.     }
  38. }
  39.  
  40. TileMap::~TileMap()
  41. {
  42. }
  43.  
  44. //Funcs
  45. void TileMap::Update()
  46. {
  47. }
  48.  
  49. void TileMap::Render(sf::RenderTarget& target)
  50. {
  51.     for (auto& x : this->Map) {  /*E2291:this range-based 'for' statement requires
  52.                      a suitable 'begin' function and none was found          
  53.                      */
  54.         for (auto& y : x) {
  55.             for (auto& z : y) {
  56.                 z.Render(target);
  57.             }
  58.         }
  59.     }
Before video 57 the project works perfectly fine.

Can anyone help me ?
4 Weeks Ago #1
Share this Question
Share on Google+
3 Replies


100+
P: 149
I would suggest you to give some context about the code here, explain what it aims to achieve, mention the errors etc.

Since you are following a tutorial series, I don't think someone would actually go through the videos to understand the stuff and answer (obviously unless they want to).
4 Weeks Ago #2

P: 6
It creates a tile map and draw color blocks into it to create a map in the game.
4 Weeks Ago #3

P: 6
Sorry for all the troubles,Visual Studio 2019 community was terrible.I've switched to Visual Studio 2019 Professional and the game works fine now.
4 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.