Thread: Seperate header files

  1. #1
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    Seperate header files

    I am making a game. I have a Player class, and some functions. When they're all in the same file, everything is fine. When I seperate them I get this:

    Underfined "RandDice()" referenced with C:\BC5\BIN\Game.obj

    (and four other errors, all the same with different functions)

    What's wrong? BTW I'm using Win98, Borland Compiler, and yes, Class functions also are refered to in the error list
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    are you including the file, #include "game.h".

    Thanks

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    code?

    it could be a number of things, so could would help.

  4. #4
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    simple example

    Here is an example that didn't work:

    Class.h:
    Code:
    #ifndef CLASS_H
    #define CLASS_H
    class Cat
    {
    	public:
       Cat(int,int);
      int Weight;
       int Age;
    };
    #endif
    Class.cpp
    [code]
    #include "Class.h"
    Cat::Cat(int w,int a)
    {
    Weight=w;
    Age=a;
    }
    Functions.h:
    Code:
    #ifndef FUNCTIONS_H
    #define FUNCTIONS_H
    
    void Something();
    
    #endif
    Functions.cpp
    Code:
    #include "Functions.h"
    
    void Something()
    {
    	cout << "Why doesn't this work? \n";
    }
    Main:
    Code:
    #include <windows.h>
    #include <iostream.h>
    #include <conio.h>
    #include "FUNCTIONS.H"
    #include "Class.h"
    int main()
    {
    	Cat cat(1,2);
       Something();
       getch();
    	return 0;
    }
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Functions.cpp needs to include <iostream.h> for access to "cout"

    gg

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    You mean you should use :
    Code:
    #include <iostream>
    using namespace std;

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    How are you compiling? If you're in an IDE, make sure all files are in the current project.

    Personally, I'm using bcc5.5 (command line compiler), I just ran command like so to compile:

    >bcc32 *.cpp

    This assumes you've added #include <iostream.h> to functions.cpp and that all files are in the same (current) directory.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    Here are the adjustments:
    Code:
    #include "Functions.h"
    #include <iostream.h>
    
    void Something()
    {
    	cout << "Why doesn't this work? \n";
    }

    Here are the errors:
    Error: Error: Unresolved external 'Cat::Cat(int,int)' referenced from C:\BC5\BIN\PROGRAMS\TESTE.OBJ
    Error: Error: Unresolved external 'Something()' referenced from C:\BC5\BIN\PROGRAMS\TESTE.OBJ
    I'm using Borland 5.02, I tried making it a project, but it said I was using the "dummy version of owl main"
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You're not linking in Functions.obj and Class.obj.

    I'm not familiar with BCC so I can't tell you how (but someone will).

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confusion on header and source files
    By dnguyen1022 in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2009, 03:42 AM
  2. including header files and implementation
    By steve1_rm in forum C Programming
    Replies: 4
    Last Post: 01-12-2009, 08:59 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. more header files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2001, 01:56 PM