Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extern is funny....

Status
Not open for further replies.

areza123

Programmer
Jul 4, 2002
60
IN
hi i have 2 C++ files say a.cpp and a main.cpp;lets say a function a() is defined and implemented in a.cpp ; i need to call this function in main()
then i should declare a() as extern void a() in main.cpp ; but this works even without extern. So what is the use of extern ?
 
You don't need to declare functions as extern. You use extern with variables, like this:

If you have a global variable

Code:
int var1;

declared in a.cpp, and you want to reference that variable in main.cpp, you'd write

Code:
extern int var1;

at the top of main.cpp. Now you can use var1 in main.cpp and it will have the same value as the var1 in a.cpp.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top