Thread: Cant Make heads or tails of .h files

  1. #1
    Registered User
    Join Date
    Feb 2002

    Unhappy Cant Make heads or tails of .h files

    Can someone please tell me how the hell header files are structered... what im trying to achieve is the time as in what time it is wen the time functino is called...


    cout << time(); // or whatever
    outputs - say "16:34:21", then, when run one second later returns "16:34:22"...

    reason im asking is that i looked in my header file, and coudlnt work out hell of it,,
    its all __ 's... cant work out what i need to put in (),

    Please can someone tell me how to make heads or tails of these files, (i read about structs etc 2 times and still its all gobbledy gook... ) and also how to get the system time at the time the fuction was called... (so not __TIME__ :)


    Borland Turbo C++ 3.0 [DOS]
    Borland Turbo C++ 3.0 For Dos

    do { war(); } while (nations == hostile);

    ... The best way to prevent wars is to have them.

  2. #2
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Is this a time.h question or a header file question?

    If you want to get the time from the clock look into time.h and the functions are in there somewhere.

    If this is a question about how to create and use header files, say what you want clearly and someone will try to help.

  3. #3
    When I save this as a .h-file:
    #ifndef __Vector2D_SEEN__
    #define  __Vector2D_SEEN__
    ///////    Vector2D.h    ///////
    class Vector2D
    { public:
         Vector2D() {}
         Vector2D(float a, float b)
         {  x=a; y=b;  }
         Vector2D difference(Vector2D& v);
         float inner(Vector2D& a);
         bool isParallel(Vector2D& v);
         bool isPerpendicular(Vector2D& v);
         bool nonzero()
             { return ( x != 0.0 || y != 0.0 ); }
         void display();
         /* other members not shown */
         float x, y;
    And this as a .C-file (the functions to the class in the .h-file):
    ////////    Vector2D.C    //////////
    #include  <iostream>
    #include  "Vector2D.h"
    float Vector2D::inner(Vector2D& v)
    {  return(x * v.x + y * v.y);   }
    void Vector2D::display()
    {   std::cout << "(" << x << ",  "
                  << y << ")";
    Vector2D Vector2D::difference(Vector2D& v)
    {    Vector2D tmp;
         tmp.x = x - v.x;
         tmp.y = y - v.y;
         return tmp;
    inline float ABS(float x)
           {  return (x > 0 ? x : -x); }
    // test if the host is perpendicular to a
    bool Vector2D::isPerpendicular(Vector2D& v)
    {   return ( nonzero() && v.nonzero()
                 && ABS(inner(v)) < 0.00000001 );    // delta = 0.00000001
    // test if the host is parallel to a (pointing in the same direction)
    bool Vector2D::isParallel(Vector2D& v)
    {   return( nonzero() && v.nonzero() &&
                x*v.x >= 0.0 &&
                y*v.y >= 0.0 &&
                ABS(x*v.y-y*v.x) < 0.00000001
    And try to compile this:
    #include <iostream>
    #include <stdlib.h>
    #include "Vector2D.h"
    Vector2D getVec(int i)  // input a point as vector
    {    float x,y;
         std::cout << "x" << i << "= ";
         std::cin >> x;
         std::cout << "y" << i << "= ";
         std::cin >> y;
         return Vector2D(x,y);
    int main()
    std::cout << "Enter vertices 0,1,2,3 "
              << std::endl;
    Vector2D p[4];
    for ( int i = 0; i < 4; i++)             // input all four points
          p[i] = getVec(i);
       Vector2D u = p[0].difference(p[3]);      // vector difference (2)
       Vector2D v;
    for (int i = 0; i < 3; i++)              // process all sides
       {  v = p[i+1].difference(p[i]);          // vector difference (3)
          if ( ! u.isPerpendicular(v) )         // check perpendicularity
          {   std::cout << "No, not a rectangle." << std::endl;
              return 1;
          u = v;
       std::cout << "Yes, a rectangle." << std::endl;
    return 0;
    It doesn't work. If I move all the functions of the .C-file to the .h-file, so that it works under one in file, the program compiles successfully. Why is this?

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    It doesn't work. If I move all the functions of the .C-file to the .h-file, so that it works under one in file, the program compiles successfully. Why is this?
    It depends on how you are building your project. What compiler are you using and how is the project set up? You may only be compiling the main source file and perhaps forgot to add in the source file containing the code for the class into the project so it isn't getting built. This would result in linking errors.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    your compiler may not find the .C extension. Try it as a .cpp extension rather than a .C.

    in the time.h file there should be a description of the tm struct as well. I admit it is a bit cryptographic, but it should be there. If not and you still want to know repost and someone will be able to post a more readable version.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. uniting all .h files in an include folder
    By afflictedd2 in forum C++ Programming
    Replies: 8
    Last Post: 11-26-2008, 01:36 PM
  2. Get .cpp and .h files to communicate...
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2008, 12:45 AM
  3. .h files: "constant already defined"
    By wakeup in forum C++ Programming
    Replies: 11
    Last Post: 11-22-2005, 05:31 AM
  4. Class files (.h and .cpp
    By Todd in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 03:07 PM
  5. creating make files
    By Unregistered in forum Linux Programming
    Replies: 4
    Last Post: 09-22-2001, 01:58 AM