#include *.h file confused me...

This is a discussion on #include *.h file confused me... within the C++ Programming forums, part of the General Programming Boards category; Good day. Is there any clear rule for how and when to include *.h ? Sometime i found some of ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    #include *.h file confused me...

    Good day.

    Is there any clear rule for how and when to include *.h ?

    Sometime i found some of the *.h work well at A.h or at A.cpp.
    Sometime i found if C.h was inclued by B.h, and i only need include B.h at A.h for the execute A.cpp. If i still included C.h at A.h. Does C.h will be compiled twice or not?

    Thanks!
    --------------------------------------------------------
    Newbie
    C/C#/C++
    swimming/cycling/running
    There is nothing more powerful than an idea.
    Except for an idea put into action.
    --------------------------------------------------------

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,788
    You are confusing me. Anyway, here's the gist of what I think you need to know:
    • Use header inclusion guards for your own headers.
    • If you need a definition from a header, include it.
    • If you need a declaration from a header, consider a forward declaration instead.
    • Do not rely on a header including another header since that fact may change under maintenance.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    i guess i understand.

    Thank you a lot!
    --------------------------------------------------------
    Newbie
    C/C#/C++
    swimming/cycling/running
    There is nothing more powerful than an idea.
    Except for an idea put into action.
    --------------------------------------------------------

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21