json_dto icon indicating copy to clipboard operation
json_dto copied to clipboard

Array issue under MSVS 15 compilation

Open itfintech opened this issue 6 years ago • 4 comments

Hello guys, I'm facing issue with array logic. Even this example: `struct data_t { std::string m_a; int m_b;

template<typename I>
void json_io(I & io)
{
	io & json_dto::mandatory("a", m_a)
		& json_dto::mandatory("b", m_b);
}

}; int main() { std::vector< data_t > e1{ { "a", 0 },{ "b", 1 },{ "c", 3 } };

//const std::string json_data = json_dto::to_json(e1);

std::string txt = R"JSON([{"a":"a","b":0},{"a":"b","b":1},{"a":"c","b":3}])JSON";
auto e2 = json_dto::from_json< std::vector<data_t> >(txt);

std::cout << "Sorted data: " << txt << std::endl;

}`

Fail with Error C2039 'json_io': is not a member of 'std::vector<data_t,std::allocator<_Ty>>' ...json_dto\pub.hpp 880

Can someone advise me what can be the issue?

itfintech avatar Jan 24 '20 08:01 itfintech

Hi!

Which version of VC++ do you use?

eao197 avatar Jan 24 '20 08:01 eao197

vs 2015 image

itfintech avatar Jan 24 '20 08:01 itfintech

Can you run cl -? from the command prompt?

I've checked the following code:

#include <vector>

#include <json_dto/pub.hpp>

struct data_t
{
	std::string m_a;
	int m_b;

	template<typename I>
	void json_io(I & io)
	{
		io & json_dto::mandatory("a", m_a)
			& json_dto::mandatory("b", m_b);
	}
};

int main() {
	std::vector< data_t > e1{ { "a", 0 },{ "b", 1 },{ "c", 3 } };

	//const std::string json_data = json_dto::to_json(e1);

	std::string txt = R"JSON([{"a":"a","b":0},{"a":"b","b":1},{"a":"c","b":3}])JSON";
	auto e2 = json_dto::from_json< std::vector<data_t> >(txt);

	std::cout << "Sorted data: " << txt << std::endl;
}

with this version of VC++: Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27032.1 for x64 It works as expected.

eao197 avatar Jan 24 '20 08:01 eao197

'cl' is not recognized as an internal or external command, operable program or batch file. I'm a VS fun, just tried in 2017 with MS Build tool v141, and works. Thx for help... Looks like in the Prerequisites from documentation refer to different VC++15.0 != VS 2015 C++14 compiler (VC++15.0, GCC 5.4 or above, clang 4.0 or above)

itfintech avatar Jan 24 '20 17:01 itfintech