Visual C++ .NET/Language Basics/Bitwise Operator
Версия от 15:31, 26 мая 2010; (обсуждение)
The bitwise or operator (|) combines the flag values
#include "stdafx.h"
using namespace System;
[ Flags ]
enum class FontFormat
{
None = 0,
BOLD = 1,
ITALIC = 2, // in binary, each represents one bit position
UNDERLINE = 4,
STRIKETHROUGH = 8,
RED = 16,
FLASHING = 32,
BOLD_ITALIC = BOLD | ITALIC // combination of two values
};
ref class Font
{
public:
property String^ Name;
Font(String^ s) { Name = s; }
};
static void SetFont(Font^ font, FontFormat format)
{
if (safe_cast<int>(format) & safe_cast<int>(FontFormat::BOLD))
{
}
if (safe_cast<int>(format) & safe_cast<int>(FontFormat::ITALIC))
{
}
};
int main()
{
SetFont(gcnew Font("Times New Roman"),FontFormat::BOLD | FontFormat::RED );
}