Advertisement Jump to content
Sign in to follow this  
luasitdown

how to access the variable

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

Advertisement
You need to pass i to setup, because it doesn't exist outside the scope of ios().

setup(int i)
{
cout<< i ;
}

ios()
{
int i = 6;
setup(i);
}

main()
{
ios();
}

will work. (so long as you put all the includes and usings in, that is)

Share this post


Link to post
Share on other sites
those braces, { and } for a little world, called a "scope" anything inside of the braces only exists in there. Stuff inside can look out, but stuff outside can't look in. You should research scope more, and the best place to do so in in "The C++ Programming Guide" by Bjarne Stroustrup, the creator of C++. It is worth every penny. I treasure my copy, ask my wife about how I am protective of it, even though I rarely need to touch it.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!