I have some old C++ code that I am trying to bring up to more modern times. At this stage, I'm trying to get code that compiled with Visual C++ 6.0 to now compile with VS 2003 (Microsoft Visual C++ .NET 69462-335-0000007-18915). If we can get this to compile cleanly & run properly, then we can take another step to get it into a more recent version of VS.
But I have found a case of an undeclared variable not being flagged by the C++ compiler! The code is something like this:
for (MLink *ML = m_Links.begin(); ML != m_Links.end(); ++ML)
{
// some code here
}
for (std::map<CString,int>::iterator it = Rows.begin();
it != Rows.end(); ++it)
{
MLink *ML = std::find (m_Links.begin(), m_Links.end(), Type);
// more code here
}
ML = m_Links.begin();
In the first for loop, ML is defined as a pointer within the loop statement. I understand this to mean that ML is undefined outside the loop.
In the second for loop, ML is defined as a pointer within the loop code block. Again, I understand this to mean that ML is undefined outside the loop.
But the last line references ML without declaring its type and the compiler gives no error (or even a warning). How can this be???
Note: the m_Links variable is a vector, and the begin() method changed in the standard library to return an iterator, rather than a pointer. So that problem is correctly flagged as an error on all three occurences.