I don't know why below code failed to compile with error:
"no instance of constructor "cb::iterator::iterator" matches the argument list argument types are:(int, const cb)"
But the code compiles fine when i uncomment the second version of constructor!
why compiler considers *this
as const?
class cb
{
public:
class iterator
{
public:
iterator(int x, cb& c):cb_(c) { x_ = x; }
//iterator(int x, const cb& c) :cb_(c) { x_ = x; }
private:
int x_;
//cb a;
const cb& cb_;
};
iterator begin() const;
};
cb::iterator cb::begin() const
{
return iterator(1, *this);
}