Strange that CFont::GetLogFont not const
-
really strange... did I oversee something? Those WinAPI stuff confuses me sometimes... but i see no reason why it can't be const. I needed a const version so I did this:
// Get LOGFONT structure
BOOL CMyFonts::GetLogFont(const CFont& Font, LOGFONT* pLogFont) const
{
ASSERT(pLogFont);
HFONT hFont = Font;
return ::GetObject(hFont, sizeof(LOGFONT), pLogFont);
} -
really strange... did I oversee something? Those WinAPI stuff confuses me sometimes... but i see no reason why it can't be const. I needed a const version so I did this:
// Get LOGFONT structure
BOOL CMyFonts::GetLogFont(const CFont& Font, LOGFONT* pLogFont) const
{
ASSERT(pLogFont);
HFONT hFont = Font;
return ::GetObject(hFont, sizeof(LOGFONT), pLogFont);
}Just look what I do. The important line can work on a const method! I am following Scott Meyers recommendations!
CSomeClass& CSomeClass::operator=(const CSomeClass& source)
{
m_name=source.m_name;LOGFONT lf; (const\_cast(static\_cast (source.m\_font)).GetLogFont(&lf)); //this is the important line m\_font.Detach(); m\_font.CreateFontIndirect(&lf); //... return \*this;
}