2011-05-07 30 views
0

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

这是我的例子。我创建了简单的测试库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 

现在我创建简单的专家的 “专家\ 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()函数调用出现以下错误:

“)” - 错误的参数计算

如果我改变了函数调用测试(0),一切编译,但我应该能够调用测试()函数没有提供任何参数,因为我有.mqh文件中第一个参数的缺省值,如下所示:void test(int i = 0); 为什么它不使用默认值?

我搜索谷歌的任何线索,但无法找到任何有关此问题的参考。有人知道吗?

回答

4

MQL Documentation指出这是不可能的:

其它模块内导入

MQL4库函数不能具有由缺省值初始化参数。