Metatrader MQL4:无法在.mqh文件中定义函数默认值

时间:2011-05-07 07:40:14

标签: mql4

我无法理解如何为我的库中的函数定义默认值。默认值往往被忽略,我得到“错误的参数计数”错误信息。

这是我的例子。我创建了简单的测试库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); 为什么它不使用默认值?

我搜索谷歌的任何线索,但找不到任何关于这个问题的参考。有人知道吗?

1 个答案:

答案 0 :(得分:4)

MQL Documentation

中所述,这是不可能的
  

在其他模块中导入的MQL4库函数不能使用默认值初始化参数。

相关问题