Common Linking Problem. Simple.

This is a discussion on Common Linking Problem. Simple. within the C++ Programming forums, part of the General Programming Boards category; All of my function calls in main of a certain class (say foo) are being marked by the linker as ...

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

    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,399
    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
    902
    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, 04:28 AM
  2. simple compiling problem
    By waxydock in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2005, 09:33 AM
  3. Probably simple problem with classes
    By slaad in forum C++ Programming
    Replies: 6
    Last Post: 12-13-2004, 11:35 PM
  4. Simple? winsock client - server problem
    By knutso in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2003, 03:51 AM
  5. Probably a simple problem
    By aristotle1 in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2001, 05:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21