简体   繁体   English

多值DWORD枚举作为一个函数参数C ++

[英]Multi Value DWORD Enum as One Function Argument C++

I am unable to get this to work. 我无法使它正常工作。 I want to include two values in the first func arg spot(Color and Black). 我想在第一个func arg spot中包括两个值(彩色和黑色)。

It works fine with one arg in arg1: func(arg_a::Color, 5); 它与arg1中的一个arg可以正常工作: func(arg_a::Color, 5);

I tried the following variations in arg1 unsuccessfully: 我在arg1中尝试了以下变体:

arg_a::Color || Black arg_a::Color && Black (arg_a::Color, arg_a::Black) DWORD test = arg_a::Color&&Black;

The documentation I have is below: arg_a Type: DWORD 我的文档如下:arg_a类型:DWORD

The arg_a can be one or more of the following values: Color White Black arg_a可以是以下值之一或多个:颜色白色黑色

To encode two "enum values" in one, you'd normally use one bit for each value: 要将两个“枚举值”合二为一,通常为每个值使用一位:

enum {
    Black = 0x01;
    White = 0x02;
    Color = 0x04;
}

Then you can combine them with bitwise operators: 然后,您可以将它们与按位运算符组合:

call(Black|White);
// or perhaps easier to read
call(Black + White);

On the receiving end 在接收端

call(int val) {
    if (val & Black) { ... }
    if (val & White) { ... }

Note this is pseudo code only. 请注意,这只是伪代码。

try DWORD(arg_a::Black, arg_a::Color) // predefined macro or (arg_a::Black|arg_a::Color) // bitwise or 试试DWORD(arg_a :: Black,arg_a :: Color)//预定义的宏或(arg_a :: Black | arg_a :: Color)//按位或

you are using logical operators but you need some bitwise operations to get this done. 您正在使用逻辑运算符,但需要一些按位运算才能完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM