Skip to content

Instantly share code, notes, and snippets.

@eiichiroi
Created April 18, 2012 15:39
Show Gist options
  • Save eiichiroi/2414420 to your computer and use it in GitHub Desktop.
Save eiichiroi/2414420 to your computer and use it in GitHub Desktop.
A little special serialize method
// g++ -I/path/to/include -L/path/to/lib -lpficommon test.cpp
#include <stdint.h>
#include <pficommon/text/json.h>
#include <pficommon/data/serialization.h>
struct Widget {
explicit Widget(int64_t value) : value_(value) {}
int64_t value_;
private:
friend class pfi::data::serialization::access;
template<typename Archive>
void serialize(Archive& ar) {
if (!ar.is_read) {
pfi::text::json::json js(new pfi::text::json::json_integer(value_));
// using namespace pfi::text::json; serialize(ar, js); // compilation error
pfi::text::json::serialize(ar, js); // compilation succeed
}
}
};
int main()
{
Widget widget(4);
std::cout << pfi::text::json::to_json(widget) << std::endl;
return 0;
}
@eiichiroi
Copy link
Author

Compiler cannot find template <> inline void pfi::text::json::serialize(json& js, json& ks) when using "using namespace pfi::text::json; serialize(ar, js);".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment