I wanted to ask for information: I was asked to pass parameters by value while, in case we are in a situation of the type
List <ExpensiveObject> list;
list.insert (expensive_object);
I don't want to pass the parameter by value.
string line;
ifstream myfile (R"(../tests/ListInteger.csv)");
if (myfile.is_open())
{
while (getline (myfile,line))
{
char c[1000];
strcpy(c, line.c_str());
List::List<int> list;
List::List<int*> listTwo;
for (int i= 0; i<line.length(); i++) {
int c48=c[i]-48;
list.insert(c48);
}
for (int i= 0; i<line.length(); i++) {
int c48=c[i]-48;
listTwo.insert(reinterpret_cast<int *>(c48));
}
list.operator+(reinterpret_cast<List::List<int> *>(&listTwo));
REQUIRE(listTwo.size() == list.size()*2);
could this management be correct? How can I handle this?
here you will find the function that deals with the insertion:
template <class T> typename List<T>::Node *List<T>::insert(T key) {
if (head == 0) {
head = new List<T>::Node(key);
this->head = head;
List<T>::current = this->head;
listSize++;
return this->head;
} else {
List<T>::Node *tempOne = new List<T>::Node(key);
List<T>::current->setnext(tempOne);
List<T>::current = List<T>::current->getnext();
listSize++;
return this->head;
}
}