i need to serailize my class.
my class looks like below
class Test
{
int m_nData;
CString m_csData;
public:
void SetData( int nData_i, CString csData_i );
void GetData( int& nData_o, CString& csData_o );
};
void Test::SetData( int nData_i, CString csData_i )
{
m_nData = nData_i;
m_csData = csData_i;
}
void Test::GetData( int& nData_o, CString& csData_o )
{
nData_o = m_nData;
csData_o = m_csData;
}
now to support serailization i changed the code as shown below
class Test : public CObject
{
DECLARE_SERIAL (Test)
int m_nData;
CString m_csData;
public:
Test()
{
}
void SetData( int nData_i, CString csData_i );
void GetData( int& nData_o, CString& csData_o );
void Serialize (CArchive& ar);
};
IMPLEMENT_SERIAL (Test, CObject, 1)
void Test::SetData( int nData_i, CString csData_i )
{
m_nData = nData_i;
m_csData = csData_i;
}
void Test::GetData( int& nData_o, CString& csData_o )
{
nData_o = m_nData;
csData_o = m_csData;
}
void Test::Serialize (CArchive& ar)
{
CObject::Serialize (ar);
if (ar.IsStoring ())
ar << m_nData << m_csData;
else
ar >> m_nData >> m_csData;
}
and in below function i am storing the Test class object to a file
void CSerailizationDlg::OnStoreButton()
{
Test TestObj;
TestObj.SetData( 1, "Testing" );
CFile file;
file.Open( "test", CFile::modeReadWrite );
CArchive arch( &file, CArchive::store );
arch << TestObj;
:
:
}
Is there anything wrong with this or missing anything?
i get the error "binary '<<' : no operator defined which takes a left-hand operand of type 'class CArchive'"
I think there is no need to overload << operator in my Test class since macros do it.
What is going wrong here?
can anyone help..plsss