C++ 符号不能在using声明中使用

C++ 符号不能在using声明中使用,c++,C++,我有一个标题,其中我的基本问题是使用关键字 #ifndef SHAPEFACTORY_H__ #define SHAPEFACTORY_H__ #include <istream> #include <map> #include <string> #include "shape.h" /* thrown when a shape cannot be read from a stream */ template<class T> class W

我有一个标题,其中我的基本问题是使用关键字

#ifndef SHAPEFACTORY_H__
#define SHAPEFACTORY_H__

#include <istream>
#include <map>
#include <string>
#include "shape.h"


/* thrown when a shape cannot be read from a stream */
template<class T>
class WrongFormatException { };

template<class T>
class ShapeFactory
{
public:
    using createShapeFunction=Shape<T>*()(void);
    static void registerFunction(const std::string &, const createShapeFunction *);
    static Shape<T> *createShape(const std::string &);
    static Shape<T> *createShape(std::istream &);
private:
    std::map<std::string, createShapeFunction *> creationFunctions;
    ShapeFactory();
    static ShapeFactory<T> *getShapeFactory();
};

#endif
\ifndef SHAPEFACTORY\u H__
#定义SHAPEFACTORY_H__
#包括
#包括
#包括
#包括“shape.h”
/*无法从流中读取形状时引发*/
模板
类错误格式化异常{};
模板
类形状因子
{
公众:
使用createShapeFunction=Shape*()(void);
静态void registerFunction(const std::string&,const createShapeFunction*);
静态形状*createShape(const std::string&);
静态形状*createShape(std::istream&);
私人:
地图创建函数;
ShapeFactory();
静态ShapeFactory*getShapeFactory();
};
#恩迪夫
我有一些我无法解决的错误

1>shapefactory.h(21): error C2873: 'createShapeFunction' : symbol cannot be used in a using-declaration
1>shapefactory.h(29) : see reference to class template instantiation 'ShapeFactory<T>' being compiled
1>shapefactory.h(21): error C2143: syntax error : missing ';' before '='
1>shapefactory.h(21): error C2238: unexpected token(s) preceding ';'
1>shapefactory.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>shapefactory.h(22): error C2143: syntax error : missing ',' before '*'
1>shapefactory.h(26): error C2065: 'createShapeFunction' : undeclared identifier
1>shapefactory.h(26): error C2059: syntax error : '>'
1>shapefactory.h(29): error C2143: syntax error : missing ';' before '}'
1>shapefactory.h(29): fatal error C1004: unexpected end-of-file found
1>shapefactory.h(21):错误C2873:“createShapeFunction”:符号不能在using声明中使用
1> h(29):请参阅对正在编译的类模板实例化“shapefactory”的引用
1> h(21):错误C2143:语法错误:缺少“;”在“=”之前
1> shapefactory.h(21):错误C2238:在“;”之前的意外标记
1> h(22):错误C4430:缺少类型说明符-假定为int。注意:C++不支持默认int
1> h(22):错误C2143:语法错误:缺少“,”在“*”之前
1> shapefactory.h(26):错误C2065:“createShapeFunction”:未声明的标识符
1> shapefactory.h(26):错误C2059:语法错误:'>'
1> h(29):错误C2143:语法错误:缺少“;”在“}”之前
1> shapefactory.h(29):致命错误C1004:找到意外的文件结尾

任何想法都很好。

编译器似乎不支持别名取消。将其替换为typedef声明。例如(至少代码已编译)

#包括
#包括
模板
阶级形态;
模板
类形状因子
{
公众:
typedef Shape*createShapeFunction(void);
静态void registerFunction(const std::string&,const createShapeFunction*);
静态形状*createShape(const std::string&);
静态形状*createShape(std::istream&);
私人:
地图创建函数;
ShapeFactory();
静态ShapeFactory*getShapeFactory();
};
int main()
{
返回0;
}

形状*()(无效)
更改为
形状*(无效)
;前者声明一个函数返回一个函数。我以前做过,我也有同样的错误。什么编译器/版本(VS根据错误消息判断,但版本更难猜测:)?看看在不同版本的VS中对不同功能的支持。特别是您希望查找我使用的VS 2012的“别名模板”。谢谢你的链接。这是我一直在寻找的!谢谢你,先生。
#include <map>
#include <string>

template <typename T>
class Shape;

template<class T>
class ShapeFactory
{
public:
    typedef Shape<T>* createShapeFunction(void);
    static void registerFunction(const std::string &, const createShapeFunction *);
    static Shape<T> *createShape(const std::string &);
    static Shape<T> *createShape(std::istream &);
private:
    std::map<std::string, createShapeFunction *> creationFunctions;
    ShapeFactory();
    static ShapeFactory<T> *getShapeFactory();
};



int main() 
{

    return 0;
}