I'm trying to implement a manipulator with one integer argument. Except for one little difference I think I'm doing exactly what is told in this guide and in this question. The only difference is that my operator is a member instead of a free function.
I'll put here just the relevant parts of my code. Some operators and other internal routines will be omitted to keep the code clean. See below:
main.cpp
#include "Display.h"
int main()
{
Display disp;
disp << position(3) << "some string here";
// ...
}
Display.h
struct manip
{
Display& (*_f)(Display&, int);
int _i;
manip(Display& (*f)(Display&, int), int i) : _f(f), _i(i) {}
};
manip position(int pos);
class Display
{
private:
int _cursor = 0;
void cursorPosition(int pos);
public:
Display& operator<<(manip& m);
friend Display& setPosition(Display& disp, int pos);
};
Display.cpp
#include "Display.h"
Display& setPosition(Display& disp, int pos)
{
disp.cursorPosition(pos);
return disp;
}
manip position(int pos)
{
return manip(setPosition, pos);
}
Display& Display::operator<<(manip& m)
{
return m._f(*this, m._i);
}
The compiler is returning this error message:
"no match for 'operator<<' (operand types are 'Display' and 'manip')"
Can someone tell me what am I doing wrong?