我无法理解如何为我的库中的函数定义默认值。默认值往往被忽略,我得到“错误的参数计数”错误信息。
这是我的例子。我创建了简单的测试库experts\libraries\test.mq4
:
void test(int i = 0) // Note the default value for "i"
{
}
然后我将.mqh
文件创建为experts\include\test.mqh
:
#import "test.ex4"
void test(int i = 0); // Note the default value for "i"
#import
现在我创建了简单的专家“expert \ simpletest.mq4”:
#include <test.mqh>
int start()
{
// Should be able to call test() function without providing any arguments,
// because it has default value.
// If I change this line to test(0), everything compiles correctly
test(); // Causes "wrong parameters count" compilation error
return(0);
}
我为test()函数调用得到以下错误:
')' - 错误的参数计数
如果我将此函数调用更改为test(0)
,则所有内容都会编译,但我应该能够在不提供任何参数的情况下调用test()
函数,因为我在.mqh文件中有第一个参数的默认值,像这样:void test(int i = 0);
为什么它不使用默认值?
我搜索谷歌的任何线索,但找不到任何关于这个问题的参考。有人知道吗?