用户定义结构的Deque

Pau*_*aul 2 c++ struct structure deque

我有一个用户定义的结构struct theName,我想制作这些结构(deque<theName> theVar)的双端队列.但是,当我尝试编译时,我收到此错误:

In file included from main.cpp:2:
Logger.h:31: error: ISO C++ forbids declaration of ‘deque’ with no type
Logger.h:31: error: expected ‘;’ before ‘<’ token
Run Code Online (Sandbox Code Playgroud)

为什么我不能这样做?

文件:Logger.h

#ifndef INC_LOGGER_H
#define INC_LOGGER_H

#include <deque>

#include "Motor.h"

struct MotorPoint {
        double speed;
        double timeOffset;
};

class Logger{
        private:
                Motor &motor;
                Position &position;
                double startTime;

(31)            deque<MotorPoint> motorPlotData;

                double getTimeDiff();
        public:
                Logger(Motor &m, Position &p);
                //etc...
};
#endif
Run Code Online (Sandbox Code Playgroud)

Pho*_*ong 9

deque的名称空间未定义:

std::deque<MotorPoint> motorPlotData;
Run Code Online (Sandbox Code Playgroud)

要么

using namespace std;
// ...

deque<MotorPoint> motorPlotData;
Run Code Online (Sandbox Code Playgroud)

  • std :: deque <MotorPoint>是更好的主意,因为在头文件中使用命令名称命令会增加包含它的文件中名称冲突的可能性. (2认同)

APr*_*mer 5

deque在命名空间std中,所以std :: deque.