I have an issue with a queue of structure which contain a template variable.
This is my code :
template <typename data_request> //Création d'un type data_request qui va contenir toute les données des structures utilisées
//!
//!\struct request_JSON
//!\detail structure for request sent to WEB_server
//! this structure is used to store request data information of data synchronized
//!
struct request_JSON{
string unique_number = "";
string request_type = "";
data_request *data;
};
queue<request_JSON<data_request>> sync_queue;
And my error is :
Video_Manager/../Commun/inc/../structuretype.hpp:465:20: error: 'data_request' was not declared in this scope
queue<request_JSON<data_request>> sync_queue;
^
Video_Manager/../Commun/inc/../structuretype.hpp:465:20: error: template argument 1 is invalid
Video_Manager/../Commun/inc/../structuretype.hpp:465:32: error: template argument 1 is invalid
queue<request_JSON<data_request>> sync_queue;
^
Video_Manager/../Commun/inc/../structuretype.hpp:465:32: error: template argument 2 is invalid
In file included from Video_Manager/../Commun/manager.hpp:5:0,
from Video_Manager/video_manager.hpp:4,
from main.cpp:11:
I understand I had to specify the type of the variable I used but I need to have different structure in data_request.
It is possible ?
My objective is to use a queue of different structure. each data_request structure can be identify by the request_type. And I had to do specific treatment on each structure.
A container like queue can have only one type. You can however store pointers. E.g.:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
struct request{
string unique_number = "";
string request_type = "";
};
template <typename data_request> //Création d'un type data_request qui va contenir toute les données des structures utilisées
//!
//!\struct request_JSON
//!\detail structure for request sent to WEB_server
//! this structure is used to store request data information of data synchronized
//!
struct request_JSON : request{
data_request *data;
};
queue<std::unique_ptr<request>> sync_queue;
//!
//!\struct request_JSON
//!\detail structure for request sent to WEB_server
//! this structure is used to store request data information of data synchronized
//!
struct request_JSON{
string unique_number = "";
string request_type = "";
string data = "";
};
queue<request_JSON> sync_queue;
where data is a string of my JSON object formated before push in the queue. With this solution I have always a string type.