Thread: help please!!!

  1. #1
    Registered User
    Join Date
    Jan 2005

    help please!!!

    hello there,
    when i was going through separate interface for implememtation where writing the classes in some file .h and the class member function in someother file .cpp.

    my question here is in the .h file. while writing the classes we tend to include #ifndef, #define and #endif. like for example

    #include DATE1_H --->> what is the need of thos ??
    #define DATE1_H  --->>                    "                    ??
    class date
            int day;
            int month;
            int year;
            date(int, int, int);
            void setdate(int, int, int);
            bool isleap();
            void printdate();
    #endif  ----->> what is the need of this??
    can any one please tell me why is that and what is the use of including that in the header file.

    thax very much

  2. #2

    The #ifdef (if defined) and #ifndef (if not defined) preprocessor commands are used to test if a preprocessor variable has been "defined". There are two common uses for this, with slightly different patterns. When there are definitions in a header file that can not be made twice, the code below should be used. A header file may be included twice other include files include it, or an included file includes it and the source file includes it again.

    To prevent bad effects from a double include, it is common to surround the body in the include file with the following (where MYHEADER_H is replaced by a name that is appropriate for your program).
    #ifndef MYHEADER_H
    #define MYHEADER_H
    . . .    // This will be seen by the compiler only once
    #endif /* MYHEADER_H */
    Additional links:

    * Added during Edit

    - Stack Overflow
    Last edited by Stack Overflow; 02-22-2005 at 09:19 PM. Reason: Added link
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  3. #3
    Registered User
    Join Date
    Jan 2005
    thaxs very much stack overflow. i understood what it is..

Popular pages Recent additions subscribe to a feed