Jump to content
  • Advertisement
Sign in to follow this  
?????????

[C++] Global array initialization

This topic is 2482 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

EDIT: Scratch this, moderator please delete this thread!
[s]Hey guys,
I know this has been talked about times before (like 3 years ago on this forum...) but I would like to revisit the idea of global array initialization inside of a function.
So given:
[source lang="cpp"]
int array[];

int main(int argc, char* argv[])
{
// Try to initialize array here...
}
[/source]
I got the idea of the following:
[source lang="cpp"]
int array[];

int main(int argc, char* argv[])
{
// Get the global array variable and try to initialize it
::array[50];
}
[/source]
Thing is, this compiles perfectly fine (on MSVC 2008). The problem is that the linker throws the following error:

error LNK2001: unresolved external symbol "int * array" (?array@@3PAMA) in file "main.obj"

Anyone have any more thoughts on this?

-David D.[/s]

Share this post


Link to post
Share on other sites
Advertisement
The ::array[50] is not initializing, its simply accessing element 50 (and doing nothing with it).

Why not just std::vector< int > array; Then array.resize(50) in main?? Then you can access array[X]. (If you are using c++)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!