The changes are all covered in detail in the MSDN document "Breaking Changes in the Visual C++ 2005 Compiler" but I'll try and give some real examples that we faced.
Pointer-to-members now require qualified name and &The compiler is much stricter about the types of function pointers. The error C3867 is generated with the following code:
The resolution is to qualify the function pointers and pass the addressof the function in. e.g.
: m_MyObserver(this, MyCallback)
: m_MyObserver(this, &CAThing::MyCallback)
const_cast can't down cast / Previously implicit stringThis code does not compile (error C2440)
casts are no longer allowed
BSTR bstrMessage = SysAllocString(T2OLE(const_castThis was replaced with the following (the BSTR could be deallocated after use):
CComBSTR bstrMessage(MyThing.ErrorMessage.c_str());This code will also give the same error:
USHORT* pString = pStringBuffer;
COM/C++ Attributes with enumeration values should not be enclosed in quotes.This code:
coclass,Should be rewritten without the quotes as:
coclass,The first time that the quotes get compiled gives warning C4581. This implies that the double quotes (") need to be replaced with single quotes ('). However, if you do this you then get error C3455. This error will say that "none of the attribute constructors matched the arguments".
Public attributes are stricterThe error MIDL2072 will be emitted for this code:
typedef [public] enum EEventIdTypeThe solution is to place the public attribute earlier:
[public] typedef enum EEventIdType
The scope of variables in control constructs is limited toIn this code:
for (int i = 0; i*max ;++i)
The scope of i is limited to the for loop. (The * is meant to be a less than operator but I'll be damned if I can get blogger to cooperate!)
Method declarations must explicitly indicate return typesThis code gives the error C4430:
virtual CheckChar(UINT maskChar, UINT nChar, int endPos);The return type must be explicitly defined. e.g.
virtual int CheckChar(UINT maskChar, UINT nChar, int endPos);
Private types are not accesible outside of the class theyThis code gives the error C2248:
are declared in
class cdxCSizingPropSheet : public CPropertySheetIn this example, the struct StandardControls needs to be available at the global scope for psheetCtrls.
static struct cdxCSizingPropSheet::StandardControls psheetCtrls =
Deprecated methodsFor security, many methods/functions that can cause buffer overruns have been deprecated. The recommended action is:
- replace the deprecated methods, or
- define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES as 1 so the compiler will use a template overload to replace the deprecated method with another. N.B. security template overloads are not available for everything. Alternatively,
- define _CRT_SECURE_NO_DEPRECATE or the warning pragma to not display this warning.
OK, that's it for now. We had a few more but I've had it with trying to lay out code in Blogger. Does anyone know any good blogging software to write code? It's damn hard from within the Blogger editor. I'm thinking of moving to my own system hosted at home for this reason alone (actually there are a few more!). If I was to move to my own system which can you recommend that do a good job of handling code?
Anyway, I hope that was useful to you - and a huge thanks to Ben who wrote most of this in our Wiki at work. The good work was his, the errors mine. :)