【发布时间】:2013-07-02 03:03:51
【问题描述】:
我正在尝试创建枚举类型到工厂对象的映射,但无法获得似乎在 MSVC9 上编译有效的代码(使用 C++03):
namespace detail {
class INoteCreator
{
public:
virtual ~INoteCreator() {}
virtual Note* create( DBHANDLE ) const {}
virtual Note* clone( DBHANDLE, Note const& ) const {}
};
template<class T>
class NoteCreator : public INoteCreator
{
public:
virtual Note* create( DBHANDLE h ) const
{
return new T( h );
}
virtual Note* clone( DBHANDLE h, Note const& n ) const
{
return new T( h, static_cast<T const&>(n) );
}
};
typedef boost::ptr_map<Note::Type, INoteCreator> Container;
static Container mapping = boost::assign::map_list_of<Note::Type, INoteCreator*>
(Note::COMPOSITE_NOTE, new NoteCreator<Note>())
(Note::HTML_NOTE, new NoteCreator<HtmlNote>())
(Note::MIME_NOTE, new NoteCreator<MimeNote>())
;
}
我遇到的错误:
错误 C2039: 'base' : 不是 'stlpd_std::priv::_DBG_iter<_container>'
错误 C2512: 'boost::ptr_container_detail::ref_pair' : 没有合适的默认值 构造函数可用
谁能告诉我为什么这不起作用并可能分享修复或解决方法?谢谢。
【问题讨论】: