Thread: Header file

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Header file

    I have cooked up a header file(i got it from the tutorial and made it into a header file) but when i compile it i get tjeis strange error, here is the code:

    Code:
    #ifndef _ANIMAL_
    #define _ANIMAL_
    
    namespace Mammal
    {
              class Animal
              {
                    public:
                           void eat();
                           void sleep();
                           void drink();
                    private:
                            int legs;
                            int arms;
                            int age;
              };
    }
    #endif

  2. #2
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    oh, i forgot, here is the error:

    Code:
    g++.exe: no input files
    
    make.exe: *** ["Animal] Error 1
    
    Execution terminated

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    right, i'm starting to think it's because i have no source files, any ideas?

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    It needs a constructor. I don't know if that's the problem, but try it anyway.

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    ok, i'll try it

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You don't compile header files. If you just want to test that the syntax is good, create a source file that includes the header, then compile that. Even better would be to create a simple main that tests the class and that you expand as you add to the class.

  7. #7
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    i tried putting a constructor and a deconstructor, do i need a deconstructor?

  8. #8
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    oh, ok

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You don't need a constructor or destructor in a class, although you almost always want a constructor. That has nothing to do with the error, though.

  10. #10
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Funny thing, i made the exact same error a couple of weeks ago and asked this very same board, scroll back a couple of pages and you can probably find the thread.

    Don't start your header name with "_" like you did, i bet you, it will fix the problem

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> i bet you, it will fix the problem
    While technically it is against the rules of the language standard, in practice this almost never causes a problem. It almost certainly was not the source of the problem here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM