抱歉,没有示例,所以我们必须在这里查看真实代码。发生的事情是,我有课CItemElem
(注意这是一个旧的来源,请不要考虑匈牙利符号、类名等)。如下例所示,我正在尝试做同样的事情CItemElem
class A
{
public:
int value;
};
int _tmain( int argc, _TCHAR* argv[] )
{
std::vector<A> hold;
A a;
hold.push_back(a);
}
尽管CItemElem
编译器在尝试使用类时给了我 C2679
vector<CItemElem>hold;
CItemElem item;
hold.push_back(item);
Error C2679: '=' binary :no operator found which takes a right-hand operand of type 'const CItemElem' (or there is no acceptable conversion)
通过单击错误,它会将我带到*_First = _Val;
此功能上的这一行xutility
template<class _FwdIt,
class _Ty> inline
void fill(_FwdIt _First, _FwdIt _Last, const _Ty& _Val)
{ // copy _Val through [_First, _Last)
for (; _First != _Last; ++_First)
*_First = _Val;
}
CItemElem 类太长且派生,因此我决定将其上传到 pastebin,而不是在这里粘贴大量代码。 Pastebin:类 CItemElem 标题 (item.h)
请注意,CItemElem 派生自 CItemBase 并且重载了 = 运算符,它也通过 CItemBase = 运算符。这是来自item.cpp
:
CItemElem& CItemElem::operator =( CItemElem & ie )
{
CItemBase::operator =( ie );