ugly workaround for another MSVC compile error

The problem is that MSVC requires n in char buf[n] to be a constant; it
cannot be computed previously. It needs to be given as a number directly
(char buf[10];) or be a const var (const int n =10; char buf[n];)
It's ugly because of manual new/delete but other than that I'd have to
dive deeper into the code it seems. If the code is being worked on, please
remove the manual memory management and, for instance,
use std::string or stringstream for the get_map() callstack instead.
This commit is contained in:
anonymissimus 2013-07-21 18:54:29 +02:00
parent b7e3b7f61a
commit f448b9c833

View file

@ -343,10 +343,13 @@ std::string ya_mapgen::create_map(const std::vector<std::string>& /*args*/) {
// }
n = createMap(); // do the job
n = (par->haut * par->larg * (YAMG_HEXLONG + 2)) + 100; // allocate buffer for result
char buf[n]; // = new char[n];
char* buf = new char[n];
n = getMap(buf); //creates the map in Wesnoth format
return buf;
const std::string result(buf);
delete[] buf;
buf = NULL;
return result;
}
#endif