I have the following constructor:
JSON(initializer_list<myType> myList){
if (end == NULL) {
for(int i=0;i < myList.size() ; i++){
end = myList(i); /* fix this */
}
}
}
end
is a struct myType
and myType
has a value struct myType *next
that points to the next struct myType
and I want to get every individual myType
from the initializer_list
so that I can put them all manually. When I write end = myList(i);
it is throwing an error, what is the correct way to get every individual value ?
You have to copy the objects out of the
initializer_list
, and you cannot index into it (because it is not designed to be used as a proper container).You can however access the members of the list in a for loop:
However,
end == NULL
might not be the correct way to test for an empty list, but I wouldn't know that without seeing the rest of the coe.