我的基于模板的工厂和工厂寄存器有问题:factory.h
#ifndef INCLUDED_FACTORY
#define INCLUDED_FACTORY
#include <map>
#include <string>
#include <boost/shared_ptr.hpp>
namespace common_utils {
template<class bT>
class Creator
{
public:
virtual bT* create() = 0;
};
template <class bT>
struct CreatorPtr
{
typedef boost::shared_ptr< Creator<bT> > type;
};
template <class bT, class cT>
class CreatorImpl : public Creator<bT>
{
public:
virtual bT* create() { return new cT; }
};
factory_register.h
#ifndef INCLUDED_FACTORYREGISTER
#define INCLUDED_FACTORYREGISTER
#include <factory.h>
namespace common_utils {
template<class eT, class bT, class cT>
class FactoryRegister
{
public:
FactoryRegister();
private:
FactoryRegister(const FactoryRegister&) {};
FactoryRegister& operator=(const FactoryRegister&) {};
};
} // namespace common_utils
现在我得到这样的编译错误:
factory_register.h:在构造函数“common_utils::FactoryRegister::FactoryRegister()”中:factory_register.h:15:错误:预期“;” 在“创造者”之前 factory_register.h:16:错误:“创造者”未在此范围内声明
似乎CreatorPtr<bT〉::type
无法识别。任何人都可以提供任何见解?谢谢。