如何增加函数中传递的枚举?
How to increment a passed enum in a function?
我正在将一个 enum 传递给一个函数。在这个函数中,我想用一些整数步骤来增加传递的枚举。我认为这是可能的,因为根据定义,enum 应该是一个整数。但由于某种原因,以下内容不起作用。
这是我的相关代码:
enum THE_ENUM {
S3,
S4,
S5,
...
};
double getPrice(THE_ENUM level) {
switch (level) {
case S3 : return mml[S3];
case S4 : return mml[S4];
case S5 : return mml[S5];
...
}
...
}
int placeOrder(THE_ENUM tPL) {
...
price = getPrice(S4); // this works
price = getPrice(tPL); // this works
price = getPrice(tPL+2); // this doesn't!
...
}
...
placeOrder(S3);
...
如何使用传递的枚举来访问第一个定义的下一个或上一个?
事实:MQL4
不是编译的 C-lang
Data of the enum type belong to a certain limited set of data. Defining the enumeration type:
enum name of enumerable type
{
list of values
};
The list of values is a list of identifiers of named constants separated by commas.
After the enumeration is declared, a new integer-valued 4-byte data type appears. Declaration of the new data type allows the compiler to strictly control types of passed parameters, because enumeration introduces new named constants. In the above example, the January named constant has the value of 0, February - 1, December - 11.
Rule: If a certain value is not assigned to a named constant that is a member of the enumeration, its new value will be formed automatically. If it is the first member of the enumeration, the 0 value will be assigned to it. For all subsequent members, values will be calculated based on the value of the previous members by adding one.
Example:
enum intervals // Enumeration of named constants
{
month = 1, // Interval of one month ---- code-assogned = 1
two_months, // Two months ---- auto-assigned ~ 2
quarter, // Three months - a quarter ---- auto-assigned ~ 3
halfyear = 6, // Half a year ---- CODE-assigned = 6
year = 12, // Year - 12 months ---- CODE-assigned = 12
wild13, // 13 months ---- auto-assigned ~13
decade =120 // Decade ---- CODE-assigned =120
};
这意味着,希望有,编译器辅助,enum
-值“算术" ( 要求有机会在 getPrice(
中调用即时 evaluated/decoded " second-value-before-wild13" )
是可能的,但不要指望它是电池-MQL4 语言架构师已准备好提供易于实现的成果,他们优化了编译语言代码以提高效率和最小延迟。
人们可以为 MQL4-enum
-s 实现自己的算法,正如上面的价格水平 double getPrice( smart_ENUM aLevelCONST )
映射器努力实现的那样,但是开发这种设计的成本,使用超出限制的语言它的局限性,是自己考虑的(不要忘记几年前的惊喜,当 string
-s 不再是 string
-s 突然,没有无论是事先通知还是前通知post,他们都会默默地成为struct
-s - 每个基金经理、交易员、支持团队成员或API-维护者可以想象震惊和噩梦,一旦事情变得毁灭性的破坏而没有机会理解为什么( string
-> struct
通知是在 [=63= 的下一个帮助文件版本中] ... 太多的头发掉了,无数的资金蒸发了,直到在帮助文件中的一条切线通知中发现了工厂崩溃的根本原因,并且 "change" 被重新分解为 API-重新设计... 我们最好不要让自己暴露在类似的无法控制的风险中[=49=] 或者宁愿不要在流沙地带与类似的 "dependencies" 一起玩野 )
至少,你被警告过了:o)
Notes :
- Unlike C++, the size of the internal representation of the enumerated type in MQL4 is always equal to 4 bytes. That is,
sizeof( months )
returns the value 4.
- Unlike C++, an anonymous enumeration can't be declared in MQL4. That is, a unique name must be always specified after the
enum
keyword.
我正在将一个 enum 传递给一个函数。在这个函数中,我想用一些整数步骤来增加传递的枚举。我认为这是可能的,因为根据定义,enum 应该是一个整数。但由于某种原因,以下内容不起作用。
这是我的相关代码:
enum THE_ENUM {
S3,
S4,
S5,
...
};
double getPrice(THE_ENUM level) {
switch (level) {
case S3 : return mml[S3];
case S4 : return mml[S4];
case S5 : return mml[S5];
...
}
...
}
int placeOrder(THE_ENUM tPL) {
...
price = getPrice(S4); // this works
price = getPrice(tPL); // this works
price = getPrice(tPL+2); // this doesn't!
...
}
...
placeOrder(S3);
...
如何使用传递的枚举来访问第一个定义的下一个或上一个?
事实:MQL4
不是编译的 C-lang
Data of the enum type belong to a certain limited set of data. Defining the enumeration type:
enum name of enumerable type
{
list of values
};
The list of values is a list of identifiers of named constants separated by commas. After the enumeration is declared, a new integer-valued 4-byte data type appears. Declaration of the new data type allows the compiler to strictly control types of passed parameters, because enumeration introduces new named constants. In the above example, the January named constant has the value of 0, February - 1, December - 11.
Rule: If a certain value is not assigned to a named constant that is a member of the enumeration, its new value will be formed automatically. If it is the first member of the enumeration, the 0 value will be assigned to it. For all subsequent members, values will be calculated based on the value of the previous members by adding one.
Example:
enum intervals // Enumeration of named constants
{
month = 1, // Interval of one month ---- code-assogned = 1
two_months, // Two months ---- auto-assigned ~ 2
quarter, // Three months - a quarter ---- auto-assigned ~ 3
halfyear = 6, // Half a year ---- CODE-assigned = 6
year = 12, // Year - 12 months ---- CODE-assigned = 12
wild13, // 13 months ---- auto-assigned ~13
decade =120 // Decade ---- CODE-assigned =120
};
这意味着,希望有,编译器辅助,enum
-值“算术" ( 要求有机会在 getPrice(
中调用即时 evaluated/decoded " second-value-before-wild13" )
是可能的,但不要指望它是电池-MQL4 语言架构师已准备好提供易于实现的成果,他们优化了编译语言代码以提高效率和最小延迟。
人们可以为 MQL4-enum
-s 实现自己的算法,正如上面的价格水平 double getPrice( smart_ENUM aLevelCONST )
映射器努力实现的那样,但是开发这种设计的成本,使用超出限制的语言它的局限性,是自己考虑的(不要忘记几年前的惊喜,当 string
-s 不再是 string
-s 突然,没有无论是事先通知还是前通知post,他们都会默默地成为struct
-s - 每个基金经理、交易员、支持团队成员或API-维护者可以想象震惊和噩梦,一旦事情变得毁灭性的破坏而没有机会理解为什么( string
-> struct
通知是在 [=63= 的下一个帮助文件版本中] ... 太多的头发掉了,无数的资金蒸发了,直到在帮助文件中的一条切线通知中发现了工厂崩溃的根本原因,并且 "change" 被重新分解为 API-重新设计... 我们最好不要让自己暴露在类似的无法控制的风险中[=49=] 或者宁愿不要在流沙地带与类似的 "dependencies" 一起玩野 )
至少,你被警告过了:o)
Notes :
- Unlike C++, the size of the internal representation of the enumerated type in MQL4 is always equal to 4 bytes. That is,
sizeof( months )
returns the value 4.- Unlike C++, an anonymous enumeration can't be declared in MQL4. That is, a unique name must be always specified after the
enum
keyword.