问题如下:
void test(const CFont &font)
{
CFont m_font;
LOGFONT logfont;
font.GetLogFont(&logfont);//有问题?
m_font.CreateFontIndirect(&logfong);}d:\t33\propertylist.h(33) : error C2662: 'GetLogFont' : cannot convert 'this' pointer from 'const class CFont' to 'class CFont &'
如果把参数中的const去掉,是可以通过
但是GetLogFont(&lpLogFont)并没有改变font中的内容,为什么不可以是const呢?
void test(const CFont &font)
{
CFont m_font;
LOGFONT logfont;
font.GetLogFont(&logfont);//有问题?
m_font.CreateFontIndirect(&logfong);}d:\t33\propertylist.h(33) : error C2662: 'GetLogFont' : cannot convert 'this' pointer from 'const class CFont' to 'class CFont &'
如果把参数中的const去掉,是可以通过
但是GetLogFont(&lpLogFont)并没有改变font中的内容,为什么不可以是const呢?
int GetLogFont( LOGFONT * pLogFont );而不是
CFont::GetLogFont
int GetLogFont( LOGFONT * pLogFont ) const;因此 const CFont& font 类型是不能够执行你的调用。另外,
font.GetLogFont(&logfont);
是将 font 的值填充到 longfont 中。