Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++&引用;X类不是模板类型;_C++ - Fatal编程技术网

C++ c++&引用;X类不是模板类型;

C++ c++&引用;X类不是模板类型;,c++,C++,我一直在处理这个问题,现在它几乎可以从编译器中得到这个错误:“类服务不是模板类型” 我一直在阅读其他论坛关于这个问题的帖子,但我没有看到任何问题(我自己,但编译器是!),能得到任何帮助吗? thx提前,这里是代码 static int aDefaultValue=0; //class T; template <typename T> class Servant { public: typedef typename T & ReferenceType; type

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

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 &);
};
static int-aDefaultValue=0;
//T类;
模板
班主任
{
公众:
typedef typename T&ReferenceType;
typedef const typename T*ConstPtrType;
typedef typename T*ptrType;
仆人(){}
ptrType analizarQos(ptrType aMetodo=0,int&aResult=aDefaultValue)
{
如果(!aMetodo)
{
aResult=-1;
返回阿米托;
}
//检查超时del metodo
//莱诺·埃尔·门萨耶信息中心
}
私人:
~Servant(){}
//避免复印机
仆人(const Servant&);
const Servant&operator=(const Servant&);
};
您需要

Servant(const Servant<T> &);
const Servant & operator=(const Servant<T> &);
仆人(const Servant&);
const Servant&operator=(const Servant&);
对于禁止的操作(至少对于不支持“注入类名”的编译器)

可能是您有一个类
Servant
的转发声明,但没有指定任何模板参数,或者模板参数的数量不正确。

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;

你能指出你从哪里得到这个错误吗?你不需要在你的typedefs中使用关键字
typename
。在你解决了那些
typename
问题之后,请。我已经解决了那些typename,但是错误还在继续…在删除
typedef
s中错误的
typename
s之后,用g++-4.6.2编译了这个。不,查找注入的class-name。对不起,这是重新定义类时的一个错误,除此之外,我已经修复了这些行,工作正常!谢谢@Ricardo_arg您使用的编译器是什么?因为这个答案对于标准C++是错误的,你可以接受,但是它被编译器接受了。“我已经解开了那些线。@juanchopanza从哪个标准开始?”?我记得我必须让复制构造函数和任何其他方法以这种方式接受对实际模板类的引用或指针,否则会出现编译错误(至少在GCC4.6x中是这样)。