Hi my example is running under Windows10 compiled with MSVC 19.28.29915., but when i try to compile with gcc 10.3 i got the following error:
error: expected primary-expression before ‘>’ token 16 | return m_formatter.Deserialize<T>(data);
Code:
converter.h
template<typename FormatType>
class Converter {
private:
FormatType m_formatter;
public:
template<typename T>
std::string Serialize(const T& data) const {
return m_formatter.Serialize(data);
}
template<typename T>
T Deserialize(const std::string& data) const {
return m_formatter.Deserialize<T>(data);
}
};
json_converter.h
class JsonFormatter {
public:
template<typename T>
std::string Serialize(const T& data) const {
const json j = data;
return std::string{ j.dump() };
}
template<typename T>
T Deserialize(const std::string& json) const {
const auto deserialized = json::parse(json).get<T>();
return deserialized;
}
};
My Converter class uses JsonFormatter to convert std::string to json.
wcon::service::Converter<wcon::service::JsonFormatter> serializer;
const test t{ 1.11, 2, 3.33, "hello there" };
const auto s = serializer.Serialize(t);
const auto deserialized = serializer.Deserialize<Test>(s);
Can somebody tell me why i dont get it. Thanks for your reply.