首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

出错: error C2678: binary '==' : no operator defined which takes a left-hand opera

2012-02-14 
出错: error C2678: binary : no operator defined which takes a left-hand operand of type???书上

出错: error C2678: binary '==' : no operator defined which takes a left-hand operand of type???
书上的例子,应该没有敲错,报错:
d:\program files\microsoft visual studio\myprojects\ex15a\student.h(35) : error C2039: 'm_strName' : is not a member of 'CString'
  d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
d:\program files\microsoft visual studio\myprojects\ex15a\student.h(35) : error C2039: 'm_nGrade' : is not a member of 'CString'
  d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
d:\program files\microsoft visual studio\myprojects\ex15a\student.h(48) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'const class CStudent' (or there is no acceptable conversion)
Error executing cl.exe.

相关的程序代码如下:
#ifndef _INSIDE_VISUAL_CPP_STUDENT
#define _INSIDE_VISUAL_CPP_STUDENT
class CStudent : public CObject
{
DECLARE_DYNAMIC(CStudent)
public:
CString m_strName;
int m_nGrade;


CStudent()
{
m_nGrade = 0;
}


CStudent(const char* szName, int nGrade) : m_strName(szName)
{
m_nGrade = nGrade;
}

CStudent(const CStudent& s) : m_strName(s.m_strName)
{
m_nGrade = s.m_nGrade;
}

const CStudent& operator = (const CStudent& s)
{
m_strName = s.m_strName;
m_nGrade = s.m_nGrade;
}

BOOL operator == (const CString& s) const
{
if((m_strName == s.m_strName) && (m_nGrade == s.m_nGrade))
{

return TRUE;
}
else
{
return FALSE;
}
}

BOOL operator != (const CStudent& s) const
{
return !(*this == s);
}

#ifdef _DEBUG
void Dump(CDumpContext& dc) const;
#endif
};




#endif


请指点,谢谢谢谢!!!!!!!!!!!!!!!!!!!!

[解决办法]

热点排行