There is no such thing as an "out" method parameter in C++.
TRM> That ain't exactly true. In MC++, it is possible to generate
TRM> a method signature that means "out", by using __gc pointers
TRM> (or pointers to pointers in the case of reference types) and
TRM> the System::Runtime::InteropServices::OutAttribute attribute.
Any example?
I think that it simpler to declare Object*& to have "ref" that to use that
attribute. There's no much difference between out and ref.
True, but then again, it makes it explicit what's going on and what's
expected of the method, which I personally think it's nice.
So, basically, you can use either Object*& or Object** to do the "ref"
thingie for reference types (with the actual type, of course, no need to use
Object explicitly); either one is exactly the same at the IL level, only
difference being an extra C++ specific custom attribute inserted by the
compiler for the *& case (which is only meaningful for the MC++ compiler,
the rest of languages ignore it).
For "out", either one would work, just add the [Out] attribute:
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
public __gc class A
{
public:
static void GetA([Out]A** a) { *a = new A(); }
};
int main()
{
A* a; A::GetA(&a);
}
This will now be understood as A.GetA(out A a) by the C# compiler.