Alright, this is a really bad one. This line of code :-
– which was compiling quite okay in VC++ 6 (and VC++ 7.1) suddenly throws this strange error message.
error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CPocket::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)'
And it also has a suggestion to fix the error that is even more confusing :-
Cast from base to derived requires dynamic_cast or static_cast
We are already using
static_cast, aren’t we?
Guess what? The return type for
OnNcHitTest has been changed from
LRESULT (only in the MFC source, the MSDN documentation still says
UINT as of Beta 2) to accommodate for negative return values. Crappy part is that this was wizard generated code – we didn’t even write it, damnit! The fix is to change
LRESULT – though if you want to compile the same code for VC++ 6 and 7.1, you’d want to do what I did :-
//In header file
#if _MSC_VER >= 1400
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg UINT OnNcHitTest(CPoint point);
//In cpp file
#if _MSC_VER >= 1400
LRESULT CPocket::OnNcHitTest(CPoint point)
UINT CPocket::OnNcHitTest(CPoint point)
#if _MSC_VER >= 1400
Took me a while to figure that one out! It’s not even listed in the Breaking Changes page! :grrr:
I’ve run into more issues than I had expected – here’s another one. Pointers to member functions now require a fully qualified name and you also need to use the & operator. It’s not a big deal really, but if your code uses pointers to members in several places, it’s a bit of a task to fix them all. I thought of writing a regular expression so I could do it in one go, but then I reckoned that it’d take me more time to come up with a safe, working regexp than it’d take me to fix all the errors manually.
m_pfnGetPixels = Get8bitPixels; //error C3867
The right way is :-
m_pfnGetPixels = &CBFile::Get8bitPixels;
I wish there was a feature to sort the compiler errors in the Output window by error number. I’ve got 400-500 files in my solution and sometimes, it’s easier for me to work on one compiler error at a time. Say I am fixing the member function pointer issue mentioned above; I’d then be able to fix the issue in all my source files and then recompile to work on the next error. Right now, I have to do a top-to-bottom error fixing and it’s a bit confusing as I am dealing with different types of errors – more strain on the brain 😦
Holy cow! Another one that’s probably going to be a pain in the neck (I am insistent on keeping this blog child-safe which is why I keep using names of the wrong parts of the body as you may have observed).
static bBusy = 0;
//error C4430: missing type specifier - int assumed.
That won’t compile either and the error message is pretty rotten – it assumes an
int, but will still throw an error. Anyway this is another step towards standards compliance, so I won’t complain too much – but if any of you guys are using pre-VC++ 2005 compilers to write code today, better make sure you don’t use this sort of code – it’ll make your future coding life a lot easier.
I am porting some VC++ 6 code to VC++ 2005 and one major pain in the neck is the for-loop variable scope. The
/Zc:forScope compiler option is on by default in VC++ 2005 and I believe it was off by default in VC++ 2003 (though people were advised to turn it on). So, code such as this won’t compile :-
for(int n=0; n<a.GetSize(); n++)
for(n=0; n<x; n++) // <- error C2065: 'n' : undeclared identifier
There’s lots and lots of similar code occurrences in the VC++ 6 code I am working on and I think the next few days are going to be fun for me! BTW, before anyone thinks I am mad at the VC++ team, this scoping rule is standard C++ behavior, so it’s not their fault at all. And that’s exactly why I am going to fix the code rather than disable the compiler option (which I can but won’t).
Okay, after some Visa delays, hurried packing and travelling, Smitha and I are in Toronto now. We haven’t fully settled down yet but it’s going to take time and we both know that too. Toronto is pretty big – specially for me, coming from Trivandrum as I am, and it’s quite similar to the US – not much difference between the USA and Canada as far as I could see. I’ve got lots of work to catch up on, lots of emails to read and reply to, and lots of settling down stuff to do here; so the next few weeks are going to be quite hectic. I’ve added a new “Toronto” category to the blog as you may have noticed, where I intend to write about my life here in Toronto with Smitha. That’s all for now 🙂