Я реализую решение из сообщения: https://stackoverflow.com/a/79433983/6319901 в моем коде.
ОС разработки: Ubuntu 24.04 LTS. >
My Target OS: VXWorks 7
язык: c ++ 17 < /p>
Я получаю приведенную ниже ошибку. < /p>
Контейнер < /p>
std::vector container;
< /code>
Ошибка оператора: < /p>
std::priority_queue mReceiveDataQueue ( {}, std::move(this->container));
< /code>
IPC Constructor < /p>
Ipc()
{
container.reserve(max_message_depth);
}
< /code>
code: < /p>
P>ipc.hpp
#pragma once
#include
#include
#include
#include
#include //For O_RDWR, O_RDONLY, O_WRONLY constants
#include //For mode constants
#include //For POSIX Message Queue
template
class Ipc
{
private:
typedef struct ipc_receive
{
std::uint32_t priority;
T2 data;
bool operator>(const ipc_receive& object) const //Check if greater
{
return this->priority < object.priority;
}
}ipc_receive_t;
std::vector container;
mutable std::mutex mReceiveMutex;
std::priority_queue mReceiveDataQueue ( {}, std::move(this->container));
void listen(void);
public:
Ipc()
{
container.reserve(max_message_depth);
}
};
template
inline void Ipc::listen(void)
{
mqd_t mqFd;
ipc_receive_t ipc_receive;
while(true)
{
ssize_t receiveLength = mq_receive(
mqFd,
reinterpret_cast(&ipc_receive.data),
sizeof(ipc_receive.data),
&ipc_receive.priority
);
if(receiveLength != -1)
{
std::lock_guard lock(this->mReceiveMutex);
this->mReceiveDataQueue.push(ipc_receive);
}
}
}
< /code>
main.cpp
#include "ipc.hpp"
struct DemoStruct
{
int a;
float b;
};
int main(int argc, char const *argv[])
{
Ipc ipc;
while (true)
{
/* code */
}
return 0;
}
< /code>
ошибка компилятора < /p>
g++ -std=c++17 main.cpp -g
In file included from main.cpp:1:
ipc.hpp:29:117: error: expected identifier before ‘{’ token
29 | std::priority_queue mReceiveDataQueue ( {}, std::move(this->container));
| ^
ipc.hpp:29:116: error: expected ‘)’ before ‘{’ token
29 | std::priority_queue mReceiveDataQueue ( {}, std::move(this->container));
| ~^~
| )
ipc.hpp:29:119: error: expected unqualified-id before ‘,’ token
29 | std::priority_queue mReceiveDataQueue ( {}, std::move(this->container));
| ^
ipc.hpp: In member function ‘void Ipc::listen()’:
ipc.hpp:56:31: error: invalid use of member function ‘std::priority_queue Ipc::mReceiveDataQueue(int)’ (did you forget the ‘()’ ?)
56 | this->mReceiveDataQueue.push(ipc_receive);
Подробнее здесь: https://stackoverflow.com/questions/794 ... rity-queue