【发布时间】:2011-05-25 10:26:07
【问题描述】:
在 C++ 中,可以将临时对象参数传递给函数:
struct Foo
{
Foo(int arg);
// ...
}
void PrintFoo(const Foo& f);
PrintFoo(Foo(10))
我正在尝试在 Visual Basic 6 中实现类似的功能:
'# Scroll bar params
Public Type ScrollParams
sbPos As Long
sbMin As Long
sbMax As Long
End Type
Public Function MakeScrollParams(pos As Long, min As Long, max As Long)
Dim params As ScrollParams
With params
.sbPos = pos
.sbMin = min
.sbMax = max
End With
Set MakeScrollParams = params
End Function
'# Set Scroll bar parameters
Public Sub SetScrollParams(sbType As Long, sbParams As ScrollParams)
Dim hWnd As Long
' ...
End Sub
但是,Call SetScrollParams(sbHorizontal, MakeScrollParams(3, 0, 10)) 会引发错误:ByRef 参数类型不匹配。为什么?
【问题讨论】:
-
公共函数 MakeScrollParams(pos As Long, min As Long, max As Long) 不应该是:Public Function MakeScrollParams(pos As Long, min As Long, max As Long) As ScrollParams?跨度>
-
没错!我忘了在函数声明后输入
As ScrollParams。谢谢!
标签: vb6