ohh, I forgot to add a static to the temp variables, how did I not notice that o.o
Thank you though :P
Seriously, just don't do that.
Let's have a look at your code.
#pragma once
#include <vector>
// don't need iostream for the header
// as a general rule, don't force consumers of a class to include something they don't need
//#include <iostream>
class MapManager
{
// do you really want map to be public?
// anyone using this class could easily overwrite the contents of it
// public:
std::vector <std::string> map =
{
"###############################################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"###############################################################"
};
// ok, this needs to be public
public:
void DrawMap();
// ugh, singleton... no need for it.
// static MapManager &GetInstance();
// don't need these, compiler will auto generate them for us
//private:
// MapManager();
// ~MapManager();
};
cpp
#include "MapManager.h"
// include iostream where it's needed
#include <iostream>
// don't need ctor or dtor
void MapManager::DrawMap()
{
// as khatharr said, but without the evil braceatendofstatement style :p
for(auto& line : map)
{
std::cout << line << "\n";
}
}
// nope nope nope nope nope
//MapManager &MapManager::GetInstance()
//{
// MapManager temp;
// return temp;
//}
and using it
MapManager map;
map.DrawMap();
so much cleaner... less code, less bugs... easy to use, hard to abuse.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight