Thread: Header Files

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    Header Files

    I understand that C++ requires both a .h and a .cpp file.

    .h file is for declaration while .cpp is where we insert all our functions.

    I have written a .h file but is unable to compile using visual C++ and can some1 point out to me if my constructor is correct.

    I have furthermore included options for my constructor. Please advise me on which one should i use as i see different coding types in books.

    #ifndef Testing_H
    #define Testing_H

    class Testing {

    public:
    Testing(); / Testing(float H, float A);
    void Test_H();
    float Test_H (float A); / float Test_H (float);
    float Test_Give (float A); / float Test_Give (float);

    private:
    float H; // I am initialising all values of H and A in .cpp file
    float A;

    };

    #endif

    can someone please give comments on it.

    Thanks
    New Self-learn kid

  2. #2
    Unregistered
    Guest
    you cant compile header files. When you compile the .cpp file and it finds the #include directive it will effectively paste the contents of the .h file into the .cpp and compile the lot. This is why header files contain declarations and only limited code (eg inline functions)

  3. #3
    Unregistered
    Guest
    I assume the name of the file is Testing.h and that it is located in the same directory as the program's exe file.

    If so I don't see an error.

    please post the associated cpp file and a driver program together with the exact wording or any errors generated by attempt at copiling.

  4. #4
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163

    ok...

    First of all if that is the real code theres plenty of mistakes. Next you declare the thing is in seemed like you had the right stnyx then save it to testing.h now for the cpp file do this...
    #include <iostream.h>
    #include "testing.h" //use " " if it is in the same directory...

    int main....

    that should work
    +++
    ++
    + Sekti
    ++
    +++

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. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 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