Stiffstream / json_dto

A small header-only library for converting data between json representation and c++ structs
BSD 3-Clause "New" or "Revised" License
149 stars 18 forks source link

Array issue under MSVS 15 compilation #6

Closed itfintech closed 10 months ago

itfintech commented 4 years ago

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?

eao197 commented 4 years ago

Hi!

Which version of VC++ do you use?

itfintech commented 4 years ago

vs 2015 image

eao197 commented 4 years ago

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.

itfintech commented 4 years ago

'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)