Решил я использовать эту библиотеку. Задача такая: сохранить массив объектов, типа скажем Person, в каждом два поля: std::string name и int age.
Почитал доки и написал следующий код.
std::map aPersons;
ofstream ofstr(fname,ios_base::out | ios_base::trunc);
rapidjson::Document doc;
rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
rapidjson::Value array(rapidjson::kArrayType);
map::iterator it,end = aPersons.end();
int i,size = aStations.size();
array.Reserve(size,allocator);
i = 0;
for (it=aPersons.begin();it!=end;it++)
it->second.saveMe(array[i++],allocator);
Соответственно, в классе Person реализован метод saveMe():
void Person::saveMe (rapidjson::Value& aValue, const rapidjson::Document::AllocatorType& anAllocator)
{
aValue.AddMember("name",name,anAllocator);
aValue.AddMember("age",age,anAllocator);
}
Строиться оно отказывается. Если верить доке и исходникам, то такие методы есть, Что я делаю не так? И как надо?
Заранее спасибо
UPD. Текст ошибки:
no matching function for call to 'rapidjson::GenericValue >::AddMember(const char [5], std::string&, const AllocatorType&)'
no matching function for call to 'rapidjson::GenericValue >::AddMember(const char [8], int&, const AllocatorType&)'
UPD2. Перенес весь код в одну функцию. Стало строиться успешно. Видимо, какая-то фигня происходит при передаче параметров.
UPD3. Проблема в передаче параметров. Не понял почему, но передать Document и Document::AllocatorType через параметры не получается. Даже при передаче через ссылку все равно не компилится. Знает кто, почему так?
https://ru-programming.livejournal.com/1359237.html