队列不是模板

0 c++ queue stl

我一直在使用C ++ STL创建代码。我想使用“队列”。因此,我编写了如下代码。但是,我遇到了“队列不是模板”错误。如您所见,我在“ Common.h”文件中编写了与队列(iostream,queue)相关的标头,并在“ DataQueue.h”文件中包含了“ Common.h”。但是,VS2013 IDE工具说“ queue m_deQueue”是错误的,因为queue不是模板。我不知道为什么..发生此错误。任何帮助表示赞赏!

//[Common.h]
#ifndef _COMMON_
#define _COMMON_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

//thread related headers
#include <Windows.h>
#include <process.h>

//socket related headers
#include <winsock.h>

#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

#endif


//[DataQueue.h]
#ifndef _QUEUE_
#define _QUEUE_

#include "SocketStruct.h"
#include "Common.h"

class CDataQueue{
private:
    static CDataQueue*                  m_cQueue;
//  deque <ST_MONITORING_RESULT>        m_deQueue;
    queue <ST_MONITORING_RESULT>        m_deQueue;
    CRITICAL_SECTION                    m_stCriticalSection;

    CDataQueue();
    ~CDataQueue();

public:
    static CDataQueue* getDataQueue(){
        if (m_cQueue == NULL){
            m_cQueue = new CDataQueue();
        }

        return m_cQueue;
    }

    deque <ST_MONITORING_RESULT> getQueue();
    void pushDataToQueue(ST_MONITORING_RESULT data);
    ST_MONITORING_RESULT popDataFromQueue();

};
#endif


//[DataQueue.cpp]
#include "DataQueue.h"

CDataQueue* CDataQueue::m_cQueue = NULL;

CDataQueue::CDataQueue(){
    ::InitializeCriticalSection(&m_stCriticalSection);
    //  m_mutex = PTHREAD_MUTEX_INITIALIZER;
}

CDataQueue::~CDataQueue(){
    ::DeleteCriticalSection(&m_stCriticalSection);
}

::deque <ST_MONITORING_RESULT> CDataQueue::getQueue(){

    return m_deQueue;
}

void CDataQueue::pushDataToQueue(ST_MONITORING_RESULT data){

    ::EnterCriticalSection(&m_stCriticalSection);
    m_deQueue.push_back(data);
    ::LeaveCriticalSection(&m_stCriticalSection);
}

ST_MONITORING_RESULT CDataQueue::popDataFromQueue(){

    ::EnterCriticalSection(&m_stCriticalSection);
    ST_MONITORING_RESULT data = m_deQueue.front();
    m_deQueue.pop_front();
    ::LeaveCriticalSection(&m_stCriticalSection);

    return data;
}
Run Code Online (Sandbox Code Playgroud)

Who*_*aig 5

坐在<queue>标准库的MS实现标题的顶部,我们发现...

// queue standard header
#pragma once
#ifndef _QUEUE_
#define _QUEUE_
Run Code Online (Sandbox Code Playgroud)

这意味着您在自己的标头围栏帖子中使用该标识符将阻止MS标头主体被拉入。因此,这std::queue对您不适用。使用不同的ID,最好是不违反用于保留给实现的宏常量使用规则的某种ID(如该ID)。

孩子们,这就是为什么我们不使用为实现使用保留的标识符的原因。有关更多信息,请阅读以下问题:“在C ++标识符中使用下划线的规则是什么?”