Thread: Common Linking Problem. Simple.

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    Common Linking Problem. Simple.

    All of my function calls in main of a certain class (say foo) are being marked by the linker as "undefined references". Here's my setup:

    foo.h:
    Code:
    #ifdef ...
    namespace foobar
    {
    class foo{...};
    namespace exception
    {
    class anexception{};
    }
    }
    #endif
    foo.cpp
    Code:
    #include "foo.h"
    using namespace foobar;
    foo::a_function()...
    . . .
    main.cpp
    Code:
    #include "foo.h"
    int main()
    {
    foo foo_instance;
    foo_instance.a_function();
    return EXIT_SUCCESS;
    }
    Where is my format wrong? What aren't I including correctly, etc?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Just a few guesses from the sample code.
    Code:
    //in foo.h
    #ifndef ...
    #define ...
    
    //in main
    #include "foo.h"
    using namespace foobar;
    int main()
    {
       foo foo_instance;
       foo_instance.a_function();
       return EXIT_SUCCESS;
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Ah! It was the namespace! Actually, while I'm at it: How do you throw and catch a class as an exception without developing an instance of that class?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc compiling and linking problem
    By maven in forum C Programming
    Replies: 6
    Last Post: 11-14-2008, 05:28 AM
  2. simple compiling problem
    By waxydock in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2005, 10:33 AM
  3. Probably simple problem with classes
    By slaad in forum C++ Programming
    Replies: 6
    Last Post: 12-14-2004, 12:35 AM
  4. Simple? winsock client - server problem
    By knutso in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2003, 04:51 AM
  5. Probably a simple problem
    By aristotle1 in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2001, 06:19 PM