1
I’m doing a project where I use many vector vectors. Only working with array vectors is easier, so I did the following function:
// add.cpp
vector <string> sAdd (string In[])
{
vector <string> Out;
Out.resize (sizeof(In));
for (int i = 0; i < sizeof(In); i++)
Out[i] = In[i];
return Out;
}
// add.h
vector <string> sAdd (string In[]);
// main.cpp
#include "add.h"
int main (void)
{
vector<string> op;
op = sAdd (string temp[3] = {
"Opcao1",
"Opcao2",
"Opcao3"
});
But the following error occurs in main.cpp: "Some argument was expected in Sadd." What I did wrong?
Note: I’m a beginner, so if you have an easier way, please tell me.
Thanks man. You know some simple way to make the variable arr[] exist only for the function. Because if not I would have to use delete [] arr, which for some reason, whenever I use my program closes alone.
– Felipe Nascimento
No, dude, you only need to use 'delete' if you instantiated the array with 'new'. The pointer is only used to reference the array in main without having to specify the amount of items. And not understood, here compiled normal. Your program displays nothing, just copies the common array elements to a vector.
– Ossetian_Odin
This time it worked. Other times, whenever I recreated the normal vector, it kept the size of the first one, but it doesn’t happen here. Thank you very much.
– Felipe Nascimento