I tried to allocate dynamic memory for an array of empty queues using the malloc function, as the code shows. However, the output of (*pq).size() is incorrect -128, and calling (*pq).push() will cause an error. Where did I go wrong? How to allocate the memory correctly?
#include <stdio.h>
#include <stdlib.h>
#include <queue>
typedef std::queue<int> iq;
iq *pq;
int main() {
pq = (iq *) malloc(16 * sizeof(iq));
printf("%d\n", (*pq).size());
printf("%d\n", (*pq).empty());
// (*pq).push(12);
(*pq).pop();
printf("%d\n", (*pq).size());
free(pq);
return 0;
}