阵列中的存储对象(Storing objects in the array)

2019-10-23 05:53发布

我想保存在地图上提升信号的对象(协会:信号名称→信号的对象)。 的信号签名是不同的,因此第二类型的地图应当提高::任何

map<string, any> mSignalAssociation;

现在的问题是如何存储对象,而不定义新的信号特征的类型?

typedef boost::signals2::signal<void (int KeyCode)> sigKeyPressed;
mSignalAssociation.insert(make_pair("KeyPressed", sigKeyPressed()));
// This is what I need: passing object without type definition
mSignalAssociation["KeyPressed"] = (typename boost::signals2::signal<void (int KeyCode)>());
// One more trying which won't work. And I don't want use this
sigKeyPressed mKeyPressed;
mSignalAssociation["KeyPressed"] = mKeyPressed;

所有这一切tryings抛出错误:

/usr/include/boost/noncopyable.hpp: In copy constructor ‘boost::signals2::signal_base::signal_base(const boost::signals2::signal_base&)’: 
In file included from /usr/include/boost/signals2/detail/signals_common.hpp:17:0, 
/usr/include/boost/noncopyable.hpp:27:7: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private 
/usr/include/boost/signals2/signal_base.hpp:22:5: error: within this context 
---------- 
/usr/include/boost/signals2/detail/signal_template.hpp: In copy constructor ‘boost::signals2::signal1<void, int&, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>::signal1(const boost::signals2::signal1<void, int, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>&)’: 
In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52:0, 
/usr/include/boost/signals2/detail/signal_template.hpp:578:5: note: synthesized method ‘boost::signals2::signal_base::signal_base(const boost::signals2::signal_base&)’ first required here 
                from /usr/include/boost/signals2.hpp:16, 
--------- 
/usr/include/boost/signals2/preprocessed_signal.hpp: In copy constructor ‘boost::signals2::signal<void(int)>::signal(const boost::signals2::signal<void(int)>&)’: 
In file included from /usr/include/boost/signals2/signal.hpp:36:0, 
/usr/include/boost/signals2/preprocessed_signal.hpp:42:5: note: synthesized method ‘boost::signals2::signal1<void, int, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>::signal1(const boost::signals2::signal1<void, int, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>&)’ first required here 
                from /home/ockonal/Workspace/Projects/Pseudoform-2/include/Core/Systems.hpp:6,

Answer 1:

这有什么好做anymap 。 升压信号仅仅是不可复制的。 您可以在一个智能指针将它们包装如shared_ptr ,如果你想要的东西,是可复制后自己清理。



文章来源: Storing objects in the array