
29 Sep
2004
29 Sep
'04
10:30 a.m.
Jonathan Turkanis wrote:
template<class> figure_out_name_offset { figure_out_name_offset operator&(nvp& p) { if (p.name() == "name") { m_address = &p.value() } } std::string* m_address; }; Person p; figure_out_name_offset f; p.serialize(f); unsigned offset = (int)f.m_address - (int)&p;
Does this force the class to represent it's fields as strings?
The above code -- yes, but I've used std::string for simplicity. I think it's possible to modify the example in such a way that you won't store an address of a variable but a formatter*, created from using address of object, address of &p.value() and depending on type of p.value() - Volodya