C
Chris Morse
Hi,
I'm trying to translate a small library written in C. Passing an
object/class parameter ByRef will result, in effect, in passing a
reference to the object reference, which is just like passing a
pointer to a pointer in C.
For example:
void build_it(Node** n)
{
// does it's thing...
}
In this case, I have in VB the following (including an example Class
definition, for clarity's sake):
Public Class Node
Public y As Double
Public left As Node
Public right As Node
End Class
Public Sub build_it(ByRef n As Node)
'Does it's thing...
End Sub
This works as expected and covers passing a reference to a reference
to a function.
My next task is RETURNING a reference to a reference.
For example, in C:
Node** work_it(Node* n)
{
// does it's thing
if(condition)
return &n.left;
else
return &n.right;
}
Converting this to VB does not seem possible. The idea here is that a
REFERENCE to the node.left or .right reference is returned so that it
can be modified by the calling function (or another function where
this return value is being passed ByRef)
I do not see any way of returning a reference to n.left or n.right in
VB - so that they can be modified.
Public Function work_it(ByVal n As Node) As ????
{
// does it's thing
If condition = True Then
Return n.left 'I want a reference to n.right, not just a copy
of the pointer n.right (as if returning ByRef and not ByVal)
Else
Return n.right ' <-- same as above
End If
}
I don't just want what n.left or n.right is pointing to, but I want a
reference to the actual n.left or n.right member variable.
Is there any facility in VB to do this? So far I have not found
one... It seems that I will be resigned to re-implementing the
algorithm since VB cannot express this directly.
Thanks!
// CHRIS
I'm trying to translate a small library written in C. Passing an
object/class parameter ByRef will result, in effect, in passing a
reference to the object reference, which is just like passing a
pointer to a pointer in C.
For example:
void build_it(Node** n)
{
// does it's thing...
}
In this case, I have in VB the following (including an example Class
definition, for clarity's sake):
Public Class Node
Public y As Double
Public left As Node
Public right As Node
End Class
Public Sub build_it(ByRef n As Node)
'Does it's thing...
End Sub
This works as expected and covers passing a reference to a reference
to a function.
My next task is RETURNING a reference to a reference.
For example, in C:
Node** work_it(Node* n)
{
// does it's thing
if(condition)
return &n.left;
else
return &n.right;
}
Converting this to VB does not seem possible. The idea here is that a
REFERENCE to the node.left or .right reference is returned so that it
can be modified by the calling function (or another function where
this return value is being passed ByRef)
I do not see any way of returning a reference to n.left or n.right in
VB - so that they can be modified.
Public Function work_it(ByVal n As Node) As ????
{
// does it's thing
If condition = True Then
Return n.left 'I want a reference to n.right, not just a copy
of the pointer n.right (as if returning ByRef and not ByVal)
Else
Return n.right ' <-- same as above
End If
}
I don't just want what n.left or n.right is pointing to, but I want a
reference to the actual n.left or n.right member variable.
Is there any facility in VB to do this? So far I have not found
one... It seems that I will be resigned to re-implementing the
algorithm since VB cannot express this directly.
Thanks!
// CHRIS