Hi everyone,
I am trying to do a map so i can build a game.
My ideia was to use a vector of vector.
I want to make a function to print the map but i donīt know how, i am just able to print the map inside the construtor.
Code:
class Map
{
public:
Map(int);
void printf(const vector <vector<int>> & );
private:
vector <vector <int> > m_map; // Could this be just map ?
};
Code:
map.cpp
#pragma once
#include <iostream>
#include <vector>
#include "Map.h"
using namespace std;
Map::Map(int size) {
if (size < 10) {
cout << "size to small, need to be at least 10x10" << endl;
return;
//TODO output to console
}
cout << "size is ok, going to create it" << endl;
vector <vector <int> > map;
// Vector of vector
for (int i = 0; i < size; i++) {
vector<int> temp;
for (int j = 0; j < size; j++) {
temp.push_back(i);
}
map.push_back(temp);
}
// Need to make in separete code.
for (unsigned int i = 0; i < map.size(); i++) {
for (unsigned int j = 0; j < map.size(); j++) {
cout << map[i][j];
}
cout << endl;
}
}
//void Map::printf(const vector <vector<int>>& map){
// for (unsigned int i = 0; i < map.size(); i++) {
// for (unsigned int j = 0; j < map.size(); j++) {
// cout << map[i][j];
// }
// cout << endl;
// }
//}
Code:
int main() {
Map myMap(22);
myMap.printf(myMap);
getchar();
return 1;
}
The error i got is the following.
no suitable user-defined conversion from "Map" to "const std::vector<std::vector<int, std::allocator<int>>,