Jump to content
  • Advertisement
Sign in to follow this  
kamikkaze

[C++] extern keyword

This topic is 3176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey again :) about extern, can I use it in a .cpp to acess variables from another .cpp file (in the same project, btw XD)? if yes, how do I extern a struct declared in this other .cpp? like... test1.h struct sLol{ (...) }; main.cpp sLol hehe; theother.cpp #include "test1.h" extern struct sLol hehe; and with that done, I'll be able to use all the stuff inside the struct in theother.cpp? ty

Share this post


Link to post
Share on other sites
Advertisement
Yes you can, but I would not recommend it since it makes it hard to figure out where the "actual" definition is. If you included the extern in test1.h then it's usually a pretty good bet that the actual definition is going to be in test1.cpp.

Remember that #include is just a complete text-replace. Basically, the complier copies all the text from the header file and pastes it into the .cpp at the point of the #include. So anything you can do in a header file, you can also do in a .cpp file (and vice versa).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!