Я реализую решение из сообщения: 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
Ошибка при назначении контейнера (std :: vector) на std :: Приоритет_queue [Duplicate] ⇐ C++
Программы на C++. Форум разработчиков
1739577443
Anonymous
Я реализую решение из сообщения: 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);
Подробнее здесь: [url]https://stackoverflow.com/questions/79438873/error-while-assigning-container-stdvector-to-stdpriority-queue[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия