很難說你的導師真的想從你那裏得到什麼,但是如果我是你的導師,我希望你瞭解Boost.Fusion Adapted Structures和它基於的技術(特別是typemaps)。
例與Boost.Fusion:
#include <boost/fusion/adapted/struct/define_struct.hpp>
#include <boost/fusion/algorithm/iteration/fold.hpp>
#include <boost/lexical_cast.hpp>
#include <iterator>
#include <list>
#include <string>
#include <iostream>
BOOST_FUSION_DEFINE_STRUCT(
(), Point,
(int, x)
(long, y)
(double, z)
)
template <class Itr> struct collector_t
{
using result_type = Itr;
template <class T>
Itr operator()(Itr itr, T const& val) const { *itr = boost::lexical_cast<std::string>(val); return ++itr; }
};
int main()
{
Point p {123, 456l, 123.456};
// create and populate the resulting list using boost.fusion facilities
std::list<std::string> strings;
auto sink = std::back_inserter(strings);
boost::fusion::fold(p, sink, collector_t<decltype(sink)>());
// dump the resulting list to prove the example
for (auto s: strings) std::cout << s << '\n';
return 0;
}
另一種猜測:您的導師希望您將「x」和「y」存儲在動態數據結構中(例如'map'),以便'getValues()'可以在運行時對條目進行迭代。 –
Pavel
但是,如果我添加像雙精度的成員屬性。地圖的概念會變得不合時宜? –
user3627590
模板怎麼樣? – Pavel