我正在从事从 VC6 到 VC9 的迁移项目。在 VC9 (Visual Studio 2008) 中,我在将 const 成员传递给接受引用的方法时遇到编译错误。它在 VC6 中编译时没有错误。
示例程序:
class A
{
};
typedef CList<A, A&> CAlist;
class B
{
CAlist m_Alist;
public:
const B& operator=( const B& Src);
};
const B& B::operator=( const B& Src)
{
POSITION pos = Src.m_Alist.GetHeadPosition();
while( pos != NULL)
{
**m_Alist.AddTail( Src.m_Alist.GetNext(pos) );**
}
return *this;
}
错误:在编译上面的程序时,我得到了错误
错误 C2664:“POSITION CList::AddTail(ARG_TYPE)”:无法将参数 1 从“const A”转换为“A &”
请帮我解决这个错误。