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