c++11模板参数,基定义的部分特殊化错误
我正在尝试实现一个通用队列fifo,但在尝试从定义为基本模板类的专门化类中选择正确的专门化类方面,我无法取得任何进展。 代码如下: 这段代码首先描述了链表的实现,因此定义了类节点和枚举类来描述将要使用的队列类型链表或固定数组,第一部分节点和GenericQueueType工作得很好,在主函数中首先定义要做一些测试。 然后,将用作包装类的包装函数没有选择为使用链表而定义的部分专门化c++11模板参数,基定义的部分特殊化错误,c++,templates,c++11,C++,Templates,C++11,我正在尝试实现一个通用队列fifo,但在尝试从定义为基本模板类的专门化类中选择正确的专门化类方面,我无法取得任何进展。 代码如下: 这段代码首先描述了链表的实现,因此定义了类节点和枚举类来描述将要使用的队列类型链表或固定数组,第一部分节点和GenericQueueType工作得很好,在主函数中首先定义要做一些测试。 然后,将用作包装类的包装函数没有选择为使用链表而定义的部分专门化 #include <iostream> #include <string> //The no
#include <iostream>
#include <string>
//The node definition used for the linked list
template<typename ValueType>
struct Node_
{
Node_(): NodePtr(nullptr)
{}
Node_(const ValueType & aValue): _Value( aValue )
,NodePtr(nullptr)
{
}
ValueType _Value;
Node_ * NodePtr;
};
//====================
enum class EQueueType
{
EQueueType_Linked_List,
EQueueType_Fixed_Queue
};
//====================
template<EQueueType,class ... TypeValue>
struct GenericQueueType
{
};
template<class TypeValue>
struct GenericQueueType<EQueueType::EQueueType_Linked_List, TypeValue>
{
GenericQueueType():TopPtr(nullptr)
,BackPtr(nullptr)
{}
void insertValueInQueue(const TypeValue & aValue)
{
Node_<TypeValue > * aPtr=BackPtr;
BackPtr=new Node_<TypeValue>(aValue );
if(TopPtr==nullptr)
{
TopPtr=BackPtr;
}
else
{
BackPtr->NodePtr=aPtr;
}
}
void getValueFromQueue(TypeValue & aValue)
{
//aErrorcode=ERROR_PROCESS;
if (TopPtr!=nullptr)
{
Node_<TypeValue > * aPtr= TopPtr;
aValue=aPtr->_Value;
aPtr->_Value ;
TopPtr=TopPtr->NodePtr;
delete TopPtr;
TopPtr=nullptr;
}
}
private:
static const int ERROR_PROCESS = -1;
static const int OK_ERROR_CODE = 0;
Node_ <TypeValue > * TopPtr;
Node_ <TypeValue > * BackPtr;
};
//base queue wrapper
template<typename QueueType, typename ... Element>
class QueueFIFO
{
};
template< template<typename ... > class QueueType,typename EQ_type,typename ... TypeElement >
class QueueFIFO<QueueType<EQ_type,TypeElement ...>,EQ_type,TypeElement ... >
{
using value_type = typename std::tuple<TypeElement...>;
static const int INITIAL_SIZE=0;
public:
QueueFIFO():_Size(INITIAL_SIZE)
{}
void enqueue(const value_type & aElement)
{
Queue.insertValueInQueue(aElement);
}
void dequeue( value_type & aElement)
{
Queue.getValueFromQueue(aElement);
}
int size(){}
private:
int _Size;
QueueType<EQ_type,TypeElement ...> Queue;
};
int main()
{
float aElement=14;
GenericQueueType<EQueueType::EQueueType_Linked_List,float> aLinkedList;
aLinkedList.insertValueInQueue(aElement);
QueueFIFO<GenericQueueType<EQueueType::EQueueType_Linked_List,float>,float> _Queue;
_Queue.enqueue(aElement);
return 0;
}
以下是编译器输出:
error: 'class QueueFIFO<GenericQueueType<(EQueueType)0, float>, float>' has no member named 'enqueue'
_Queue.enqueue(aElement);
^
我一直在《标准》杂志上读到:
在引用类模板专门化的类型名称中,例如。,
A参数列表应与模板参数匹配
主模板的列表。的模板参数
专门化是从主模板的参数推导出来的。
14.5.5.1
但我仍然看不出错误。
提前谢谢
QueueFIFO的部分专门化中定义的排队采用常量&value\u类型,其中value\u类型为std::tuple。您试图用一个浮动的AEElement调用它,而您应该给它传递一个std::tuple。尝试将std::make_tupleElement传递到排队
此外,正如T.C.在评论中指出的,您使用typename EQ_type并传入EqualeType类型的枚举值的位置是错误的-枚举值与模板类型参数不匹配。为此,您必须使用非类型参数,正如您在GenericQueueType的定义中所做的那样。问题在于模板参数中的某个地方没有实际创建专门化。如果您仅使用一个;而不是一个空的定义 简单的回答是不要使用模板参数;您编写的代码不需要它们,事实上,也不需要对该模板进行任何专门化,而且您不太可能看到需要它们的情况。在这种情况下,消除可能有用的情况实际上是有害的。EQueueType::EQueueType\U Linked\U List不是一种类型,因此您的部分专门化与QUEUEFIO不匹配。