CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: about #define

  1. #1
    Join Date
    Mar 2009
    Posts
    9

    Question about #define

    Hi, all

    I have a question about the following header file
    I don't understand why #define is used
    Does anyone know what's the purpose of it?

    Thanks

    Kai


    // Kai.h

    #ifndef KAI_CLASS1_H
    #define KAI_CLASS1_H

    namespace Kai
    {
    class class1 {
    ...
    } ;
    }

    #endif

  2. #2
    Join Date
    Apr 2009
    Posts
    21

    Re: about #define

    Code:
    #ifndef HEADER_NAME_H
    #define HEADER_NAME_H
    // ...
    #endif
    Those are things that are added to header files to avoid re-definition of its contents. It is a convention now to add that every single time you create a header file.

    Suppose you have a file A.cpp that includes a file B.h at the start of a program (or anytime). Then later on a file C.cpp also includes that file B.h.

    What will happen in this case? "Compiler error! Redefinition of xxx & xxx & ..."

    Those headers prevent that from happening.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured