Jump to content
  • Advertisement
Sign in to follow this  
TiitHns

simple variable question

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

Question about variables getting lost. Is it possible. void f(int &value) { //value 0(missing at this point) } int main(void) { int val = 10; if(val) f(10); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Passing an integer literal to f() isn't even possible the way it is defined in your snippet. You'd have to change the signature of f() to

void f(const int& value);


Apart from that, I don't really understand your question. What variable exactly is getting 'lost'?

Share this post


Link to post
Share on other sites
Forgive me if i'm wrong, but i'm working on the assumption that this is C/C++ code. The & symbol in front of value is the address of or reference to operator, which is going to say address of the integer value 10, you should be able to just use int value. so when you try to use the variable 'value' it's not really there, it's jus Also, i'm not sure what the code here is to accomplish, some context may help.

For example this segment of code:


int main(void)
{

int val = 10;

//this if statement seems entirely useless
if(val) f(10);

return 0;
}


the if statement here will always process f(10) because you've set val = 10, i imagine you're trying to do something more like


if (val == f(10))
{
//do stuff
}



Again, forgive me if i'm wrong, a little more information would be greatly useful here though. From your code it looks like you want to pass it the value 10, not a reference to the value.

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!