Created
April 18, 2012 15:39
-
-
Save eiichiroi/2414420 to your computer and use it in GitHub Desktop.
A little special serialize method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler cannot find template <> inline void pfi::text::json::serialize(json& js, json& ks) when using "using namespace pfi::text::json; serialize(ar, js);".