不幸的是,我正在使用 c++98。
template <class bT>
class Creator
{
public:
virtual bT* create() = 0;
};
template <class bT>
struct CreatorPtr
{
typedef boost::shared_ptr< Creator<bT> > ptr;
};
template <class bT, class cT>
class CreatorImpl : public Creator<bT>
{
public:
virtual bT* create() { return new cT; }
};
template <class bT>
class Factory
{
public:
virtual bT* create(const std::string& name) = 0;
virtual ~Factory() { _table_creator.clear(); }
protected:
Factory() {}
Factory(const Factory&) {}
Factory &operator=(const Factory&) { return *this; }
void registerCreator(const std::string& name, typename CreatorPtr<bT>::ptr creator)
{ _table_creator[name] = creator; }
typedef std::map<std::string, typename CreatorPtr<bT>::ptr> tableCreator;
typedef typename tableCreator::const_iterator citerTc;
......
protected:
tableCreator _table_creator;
};
我有错误
“错误:“typedef typename tableCreator::const_iterator citerTc;”上的“tableCreator”之前的预期嵌套名称说明符;” 线。我正在使用 4.1.2 g++。”
对不起大家,我这里漏掉了typename"pointed by syam",删掉了citerTc定义中的模板。现在代码编译并运行良好。感谢大家的帮助。