×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

include vs import

include vs import

include vs import

(OP)
Is that when ever I want to call any function or use any Class ojbect
/ structure, I will include that .h header file that contain that
Class object?

include <winsock.h>;

It's basically same as Java where I important the Class whenever I
want to use that Class -

import java.lang.String;

RE: include vs import

Yes but not exactly the same.  Include files are used for all sorts of things, one of which is class definitions.  They are also used for external function definitions, inline coding, templates, general declarations, macro definitions.

You may sometimes see include files being brought in more than once.  eg

CODE

// include file elist.h
ETYPE(E8, "ATE")
ETYPE(E2, "TO")
ETYPE(E4, "FOUR")
ETYPE(E0, "NOT")
ETYPE(E1, "WAN")
ETYPE(E3, "TREE")

// Code file
#define ETYPE(e,v) e,
enum EType
{
#include "elist.h"
   ETypeMax
}
#undef ETYPE

#define ETYPE(e,v) #e "=" v,
const char* estr[] =
{
#include "elist.h"
   ""
};
#undef ETYPE

RE: include vs import

#include <file> just copies everything inside <file> and inserts it at the location where the #include line is.
So if you have a header like this:

CODE

class Test
{
public:
   Test();
...
};
and a .cpp file like this:

CODE

#include "Test.h"

Test::Test()
{
   // Initialize the Test object...
}
...
When you compile it, the pre-processor combines it into this:

CODE

class Test   // This used to be:  #include "Test.h"
{
public:
   Test();
...
};

Test::Test()
{
   // Initialize the Test object...
}
...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close