Hi everybody,
i was writing a small c++ class that uses a list as a data member , i then wrote a small print function to print the numbers in the list
#include <iostream>
#include <string>
#include <sstream>
#include <list>
using namespace std;
class A
{
private:
list<int> number;
string ConverttoS(int) const;
public:
A();
string print();
};
string A::ConverttoS(int input) const
{
std::stringstream out;
out << input ;
return out.str();
}
string A::print()
{
string output = "";
list<int>::iterator i;
for(i = number.begin() ; i != number.end() ; ++i)
output = output + ConverttoS(*i);
return output;
}
everything is working fine until i decided to set the print member function as a const , since it is not modifying anything and it is only calling const data members but when i did that , the compiler gave the following error:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::list<int,class std::allocator<int> >::const_iterator' (or there is no acceptable conversion)
error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::list<int,class std::allocator<int> >::const_iterator' (or there is no acceptable conversion)
it is not a big deal i can simply remove the const keyword from the implementation and declaration and everthing will work fine , but i am only curious to know why this is happening