Is there an equivalent to the C# 'out' keyword for out parameters but in C++?
I'd like to have a constructor also set a couple of references to variables where it is called.
You can use the out keyword in two contexts: As a parameter modifier, which lets you pass an argument to a method by reference rather than by value. In generic type parameter declarations for interfaces and delegates, which specifies that a type parameter is covariant.
ref is used to state that the parameter passed may be modified by the method. in is used to state that the parameter passed cannot be modified by the method. out is used to state that the parameter passed must be modified by the method.
No direct equivalent. In C++ you choose between passing by value, passing a pointer value, or passing a reference parameter. The latter two can be used to get data back from function.
VOID foo(int* pnA, int& nB)
{
*pnA = 1;
nB = 2;
}
int nA, nB;
foo(&nA, nB);
// nA == 1, nB == 2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With