When I try to call a friend function of a certain class by passing a reference to an object of said class via de-referencing the "this" pointer, Eclipse throws a type-mismatch error but the program still compiles and runs just fine.
To see if this was something exclusive to Eclipse I tried running the code with a few online compilers as well. onlinegdb and codechef compiled and ran without showing any errors. Since the program technically works I could just ignore this error and move on but since I don't want to run into any undefined behavior in the future, it might be best to get this sorted out right now.
#include <iostream>
class Foo
{
public:
Foo ()
{
Bar (*this); //<---The error occurs on this line
}
friend void Bar (Foo &);
};
void Bar (Foo &foo)
{
std::cout << "Inside Bar()!" << std::endl;
}
int main ()
{
Foo foo;
}
Error message:
Invalid arguments '
Candidates are:
void Bar(Foo &)
'