Thread: Strange compiler error

  1. #1
    Registered User
    Join Date
    Jan 2008

    Strange compiler error

    #include <iostream>
    class foo {
        foo() { std::cout << "foo"; }
        void bar() { std::cout << "bar"; }
    int main() {
        foo f();;
    For some reason I get the error "left of '.bar' must have class/struct/union". Does anyone know why?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Does changing the line above to foo f; help?

    (Edit: Perhaps g++'s error message will give you more of my point:
    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.)
    Last edited by tabstop; 10-21-2008 at 08:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM