0

我一直在处理这个问题,现在它几乎准备好从编译器得到这个错误:“类仆人不是模板类型”我一直在阅读其他论坛关于这个问题的帖子,但我没有看到任何问题(我自己但是编译器是的!),可以得到任何帮助吗?提前谢谢,这是代码

static int aDefaultValue=0;
//class T;
template <typename T>
class Servant
{
public:
    typedef typename T & ReferenceType;
    typedef const typename T * ConstPtrType;
    typedef typename T * ptrType;
    Servant(){}

    ptrType analizarQos(ptrType aMetodo= 0,int & aResult = aDefaultValue)
    {
        if (!aMetodo)
        {
            aResult=-1;
            return aMetodo;
        }
        //check for timeout del metodo
        //lleno el mensaje con la info

    }

private:
    ~Servant(){}
    //avoid copias
    Servant(const Servant &);
    const Servant & operator=(const Servant &);
};
4

2 回答 2

1

你需要

Servant(const Servant<T> &);
const Servant & operator=(const Servant<T> &);

对于禁止的操作(至少对于不支持'injected-class-name'的编译器)。

可能是你有一个类的前向声明Servant,没有指定任何模板参数,或者那里的模板参数数量错误。

于 2013-08-09T13:00:35.280 回答
0

Clang 打印出来

/private/tmp/my.cpp:7:22: error: expected a qualified name after 'typename'
typedef typename T & ReferenceType;
                 ^
/private/tmp/my.cpp:8:28: error: expected a qualified name after 'typename'
typedef const typename T * ConstPtrType;
                       ^
/private/tmp/my.cpp:9:22: error: expected a qualified name after 'typename'
typedef typename T * ptrType;
                 ^
3 errors generated.

我更改为后编译的代码:

typedef T & ReferenceType;
typedef const T * ConstPtrType;
typedef T * ptrType;
于 2013-08-09T20:11:41.853 回答