Thread: question about header files

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    61

    question about header files

    Say I had the following code:

    Test.h
    Code:
    class test
    {
      public:
    
        test();
        ~test();
        void dis();
    };
    Test.cpp
    Code:
    #include <iostream>
    #include "Test.h"
    
    test::test()
    {
    }
    
    test::~test()
    {
    }
    
    void test::dis()
    {
        std::cout<<"Hello";
    }
    main.cpp
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include "Test.h"
    
    using namespace std;
    
    int main()
    {
        test a;
        a.dis();
        system("PAUSE");
        return 0;
    }
    Each time i try to compile main.cpp it dosn't compile and my compiler just says:

    c:\windows\TEMP\cc1l***b.o(.text+0x29):main.cpp: undefined reference to `test::test(void)'
    c:\windows\TEMP\cc1l***b.o(.text+0x40):main.cpp: undefined reference to `test::~test(void)'
    c:\windows\TEMP\cc1l***b.o(.text+0x57):main.cpp: undefined reference to `test::dis(void)'
    c:\windows\TEMP\cc1l***b.o(.text+0x86):main.cpp: undefined reference to `test::~test(void)'

    What's going on?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    Hi

    the errors are not generated at compile time, they are produced by the linker.
    did you add the Test.cpp to your project or if you use a command line mode to build your executable try to add the Test.cpp too.

    damyan

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    61

    oops!

    I forgot completely about adding it to the project!
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Header files in .h
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 08:58 AM
  3. quick question about header files
    By linucksrox in forum C++ Programming
    Replies: 11
    Last Post: 08-24-2005, 09:24 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Header files
    By borland_man in forum C++ Programming
    Replies: 14
    Last Post: 02-22-2002, 04:30 AM