<分区>
我一直在尝试计算我正在转换为 JAVA 的这部分 C++ 代码。方法调用 PrintItem()
将 DWORD
作为第二个参数,但在这个特定示例中它允许同时使用 enum
中的两个元素?
我指的是 following answer通过 Ashish试图得到一些澄清,但没有太大帮助。
enum
{
PRINT_ENTRY = 0x0001,
PRINT_PREPEND = 0x0002,
PRINT_APPEND = 0x0004,
PRINT_PRECOMMENTS = 0x0008,
PRINT_POSTCOMMENTS = 0x0010,
PRINT_SPECIAL = 0x0010,
PRINT_DEFAULT = PRINT_ENTRY | PRINT_PREPEND | PRINT_APPEND | PRINT_PRECOMMENTS | PRINT_POSTCOMMENTS | PRINT_SPECIAL
};
传入两个枚举元素的方法调用?这是我不明白的。
bResult = PrintItem( pMergeItem, PRINT_PREPEND | PRINT_ENTRY );
方法声明
bool PrintItem( CItem* pItem, DWORD options = PRINT_DEFAULT );
还有定义,稍微精简了一点:
// Prints an individual item to the invoice (based on appropriate template settings)
bool CPrintRptInvoice::PrintItem( CItem* pItem, DWORD options )
{
bool bResult = true;
CString strKey = GetItemKey( pItem );
DWORD getOpts = CPrintTemplate::GE_NONE;
if ( options & PRINT_ENTRY )
getOpts |= CPrintTemplate::GE_ENTRY;
if ( options & PRINT_PREPEND )
getOpts |= CPrintTemplate::GE_PREPEND;
if ( options & PRINT_APPEND )
getOpts |= CPrintTemplate::GE_APPEND;
CString strEntry = m_pTemplate->GetEntry( strKey, getOpts );
// print any prefix first
if ( options & PRINT_PRECOMMENTS )
PrintComment( pItem->GetInvoicePrefix() );
// print main entry
if ( strEntry.IsEmpty() )
{
if ( ( options & PRINT_ENTRY ) && !m_pTemplate->EntryExists( strKey ) )
{
//Code to print Entries, not touching options anymore.
}
}
// print any special cases
if ( bResult && ( options & PRINT_SPECIAL ) )
{
//Code to print special cases, not touching options anymore...
}
// print any suffix last
if ( options & PRINT_POSTCOMMENTS )
PrintComment( pItem->GetInvoiceSuffix() );
return bResult;
}
我的问题是 - 它是如何处理枚举的多个参数的?我没有看到它处理该方法定义中的任何内容!我修剪掉的内容根本没有触及 options
。
我想我很困惑,因为我将 options
视为某种集合,不是吗?那么,您如何才能做到这一点并获得正确的元素:if (options & PRINT_PRECOMMENTS)
..