I'm implementing a linked list. I'm getting the error:
P1LinkedList.cpp:145: error: call of overloaded ‘to_string(int&)’ is ambiguous
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:2604: note: candidates are: std::string std::to_string(long long int)
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:2610: note: std::string std::to_string(long long unsigned int)
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:2616: note: std::string std::to_string(long double)
(I'm compiling my code with g++ -std=c++0x
The method throwing this exception:
std::string P1LinkedList::print(){
std::string print = "";
iterator itr = begin();
for(int i = 0; i < theSize; i++){
print += std::to_string(itr.current->data) + " ";
itr++;
}
return print;
}
current
is the current Node being pointed to by the iterator. data
is an int
that is within the Node class.
Node.h:
#ifndef Node_h
#define Node_h
struct Node{
int data;
Node* next;
Node* prev;
Node(const int & d = 0, Node *p = 0, Node *n = 0);
};
#endif
Part of my const_iterator.h file where current
is declared (my iterator
class extends from the '''const_iterator''' class:
protected:
Node *current;
int& retrieve() const;
const_iterator(Node*p);
friend class P1LinkedList;
};
I'm trying to pass data
through to_string
as a regular int
value, which I thought itr.current->data
was doing, but could I possibly be getting this error because it's not passing the int value of data, but a pointer to it instead?
Aucun commentaire:
Enregistrer un commentaire