I am trying to push something like a mixed array to a stack. That means I want to push an array with a string and an Integer, but I get the following error message:
no matching function for call to 'StackArray<String []>::push(runThrough(String*, int)::command_type [2])'
This is my code:
#include <StackArray.h>
//...
String runThrough(String lines[], int lnnum) {
String res = "";
StackArray <String> commands;
for (int i = 0; i < lnnum; i++) {
if (isCommand(lines[i]) && lines[i].substring(4, 5) == "0") {
typedef struct {
String com;
int pos;
} command_type;
command_type command[2];
command[0].com = lines[i];
command[0].pos = i;
commands.push(command);
}
}
//...
}
return res;
}
"lines" is an array which consists of multiple bytes in the form of a String, because this option is more comfortable for me. "lnnum" is the length of that array.
I want to push lines[i ] and i to the stack.
The only solution that would come to my mind is to convert i to a String, but that wouldn't be that elegant.
Is there any way to push a struct array or two variables of different data types at the same time to a stack?
StackArray is a template class and you have declared it like this:
StackArray<String> commands;
Therefore you can only push items that are of type String to the commands stack.
Also, it is preferred not to use a typedef for struct. Rather declare it like this:
struct command_type {
String com;
int pos;
};
If you want to push a command onto the commands stack then move your struct declaration outside of the block and declare StackArray using the command_type struct like this:
struct command_type {
String com;
int pos;
};
StackArray<command_type> commands;
Not sure why you are declaring a 2 element array of command when you are only using the first element. However, you are trying to push the array command, rather than a single element. Try this: