I have this code:
CCalcArchive::CCalcArchive() : m_calcMap() { }
m_calcMap is defined as this:
typedef CTypedPtrMap<CMapStringToPtr, CString, CCalculation*> CCalcMap; CCalcMap& m_calcMap;
When I compile in Visual Studio 2008, I get this error:
error C2440: 'initializing' : cannot convert from 'int' to 'CCalcArchive::CCalcMap &'
I don’t even understand where it gets the ‘int’ error from, and also why this doesn’t work? It feels like I’m actually having some sort of syntax error, but isn’t this how member initialization lists are supposed to be used? Also, AFAIK, the MFC class CTypedPtrMap has no constructor taking arguments.
The
intis coming from the fact thatCTypedPtrMaphas a constructor that takes anintargument that is defaulted to 10.The real problem that you’re running into is that the
m_calcMapreference initalization you have there is trying to default construct a temporaryCTypedPtrMapobject to bind the reference to. However, onlyconstreferences can be bound to temporary objects. No doubt the error message is not very informative.But even if the
m_calcMapmember were aconstrefernce, you’d still have a problem binding it to a temporary. in this case, the MSVC 2008 compiler gives a pretty clear warning: