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
现在我创建简单的专家“experts\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); 为什么不使用默认值?
我在谷歌上搜索任何线索,但找不到有关此问题的任何参考资料。有人知道吗?
I can't understand how to define default values for functions in my library. Default values tend to be ignored and I get "wrong parameters count" error message.
Here is my example. I created simple test library experts\libraries\test.mq4
:
void test(int i = 0) // Note the default value for "i"
{
}
Then I created .mqh
file as experts\include\test.mqh
:
#import "test.ex4"
void test(int i = 0); // Note the default value for "i"
#import
Now I create simple expert "experts\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);
}
And I get the following error for test() function call:
')' - wrong parameters count
If I change this function call to test(0)
, everything compiles, but I should be able to call test()
function without providing any parameters, because I have default value for first parameter in .mqh file, like this: void test(int i = 0);
Why it doesn't use the default value?
I search google for any clue, but can't find any references about this problem. Anybody knows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 MQL 文档 中所述,这是不可能的:
This is not possible as stated in the MQL Documentation: