boomshanker
asked on
Newbie problem with SerializeElements
Hi
I'm getting the following error while implementing SerializeElements:
"'CArchive::CArchive': cannot access protected member declared in class 'CArchive'"
This is the code I am using:
template <>
void AFXAPI SerializeElements <CStockData>
( CArchive& ar, CStockData* pNewSD, int nCount )
{
for ( int i = 0; i < nCount; i++, pNewSD++ )
pNewSD->Serialize( ar );
}
and it is defined in the header as:
template <>
void AFXAPI SerializeElements <CStockData>
( CArchive& ar, CStockData* pNewSD, int nCount );
outside of the class declarations.
The SerializeElements code is sitting in a class (CStockDataList: public CList< CStockData, CStockData & > ) that adds CStockData objects (derived from CObject) to a list. The StockData.h has been included in StockDataList.h as well as afxtempl.h for CList.
CStockData has been serialised by using
IMPLEMENT_SERIAL(CStockDat a, CObject, 1) in the .cpp and
DECLARE_SERIAL(CStockData) in the .h
I use the following code for CStockData Serialize (All data members are protected):
void CStockData::Serialize(CArc hive ar)
{
if (ar.IsStoring ())
ar << m_date << m_dblPrice << m_strFund;
else
ar >> m_date >> m_dblPrice >> m_strFund;
}
I'm still pretty new to MFC so I'm not really sure what the error message is trying to tell me, or if I'm even looking in the right place for the solution. I've looked in the MSDN and the code I'm using for SerializeElements seems to be correct, so I'm stumped as to what I'm missing.
Any help would be greatly appreciated.
Thanks in advance.
I'm getting the following error while implementing SerializeElements:
"'CArchive::CArchive': cannot access protected member declared in class 'CArchive'"
This is the code I am using:
template <>
void AFXAPI SerializeElements <CStockData>
( CArchive& ar, CStockData* pNewSD, int nCount )
{
for ( int i = 0; i < nCount; i++, pNewSD++ )
pNewSD->Serialize( ar );
}
and it is defined in the header as:
template <>
void AFXAPI SerializeElements <CStockData>
( CArchive& ar, CStockData* pNewSD, int nCount );
outside of the class declarations.
The SerializeElements code is sitting in a class (CStockDataList: public CList< CStockData, CStockData & > ) that adds CStockData objects (derived from CObject) to a list. The StockData.h has been included in StockDataList.h as well as afxtempl.h for CList.
CStockData has been serialised by using
IMPLEMENT_SERIAL(CStockDat
DECLARE_SERIAL(CStockData)
I use the following code for CStockData Serialize (All data members are protected):
void CStockData::Serialize(CArc
{
if (ar.IsStoring ())
ar << m_date << m_dblPrice << m_strFund;
else
ar >> m_date >> m_dblPrice >> m_strFund;
}
I'm still pretty new to MFC so I'm not really sure what the error message is trying to tell me, or if I'm even looking in the right place for the solution. I've looked in the MSDN and the code I'm using for SerializeElements seems to be correct, so I'm stumped as to what I'm missing.
Any help would be greatly appreciated.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're wellcome at any time!
Kender
Kender
ASKER
I had actually given up on this project (and almost on MFC!!!).
You were right on the money. I was using CArchive ar instead of &ar. As soon as I changed that, it worked.
Thanks again.