符号不能在使用声明中使用 [英] symbol cannot be used in a using-declaration

查看:310
本文介绍了符号不能在使用声明中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've got a header in which my base problem is with the using keyword.

#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

我有一些错误, t解析。

And I've got some errors which I can't resolve.

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

任何想法都会很棒。

推荐答案

看起来编译器不支持别名声明。将其替换为typedef声明。例如(至少编译代码)

It seems that the compiler does not support the alias decladation. Substitute it for a typedef declaration. For example (at least the code is compiled)

#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;
}

这篇关于符号不能在使用声明中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆