-
Strange compiler error
Code:
#include <iostream>
class foo {
public:
foo() { std::cout << "foo"; }
void bar() { std::cout << "bar"; }
};
int main() {
foo f();
f.bar();
};
For some reason I get the error "left of '.bar' must have class/struct/union". Does anyone know why?
-
Does changing the line above to foo f; help?
(Edit: Perhaps g++'s error message will give you more of my point:
Code:
temp.cpp.11: error: request for member `bar' in `f', which is of non-class type `foo ()()'
That is to say, foo f(); does not declare an instance of class foo, but is a prototype for a function.)