Returning values through params
Aug 21, 2010 at 1:33am UTC
Hello, i need help solving this problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void main(){
int length = 0;
getNumbs(length);
std:: cout << length << std::endl;
system("Pause" );
}
void getNumbs(__out int leng){
leng = 20;
}
I am trying to return a value through the parameter leng, but the program always prints out 0, what am i doing wrong?
Last edited on Aug 21, 2010 at 1:35am UTC
Aug 21, 2010 at 1:56am UTC
__out is not C++. Use the reference declaration: &
1 2 3 4
void getNumbs(int & leng){
leng = 20;
}
Aug 21, 2010 at 2:04am UTC
Thanks Galik, that worked, but i see __out used all the time, and it causes no errors to my code. Im pretty sure that it is just a windows macro used to say that a param is used to return a value, not as an input value, it could be helpful to you to organize your code or something.
So:
1 2 3 4
void getNumbs( __out int & leng){
leng = 20;
}
is the same as:
1 2 3 4
void getNumbs( int & leng){
leng = 20;
}
Thanks again!
Aug 21, 2010 at 2:12am UTC
That it is an output parameter goes without saying.
If it weren't, it should be a const reference.
Topic archived. No new replies allowed.