Allow the use of a variable in the local scope

I am considering a large project where variables declared in statements for

are used out of scope. VS2013 doesn't like it and gives compiler errors.

How can I tell VStudio about this?

for (CBookmarks::iterator it = m_listBookmarks.begin();
    !(it==m_listBookmarks.end()) && hSelected!=it->hParent;
    it++);

CString Hierarchy = LookupHierarchy(it->hParent);

      

This is a large project that I do not support. I am just reading the source code and trying to run it as a link for a new project. I don't want to "fix" the code base.

Edit

For some reason I am still getting compilation errors despite setting:

enter image description here

I tried changing https://msdn.microsoft.com/en-us/library/84wcsx8x.aspx?f=255&MSPPError=-2147217396 but I still get compilation errors.

+3


source to share


1 answer


Using:

/Zc:forScope-

      

As described: https://msdn.microsoft.com/en-us/library/84wcsx8x.aspx



But I really hate the idea of ​​using a switch like this. I would suggest simply using the following change, which will have the same effect:

CBookmarks::iterator it = m_listBookmarks.begin();
for (;
    !(it==m_listBookmarks.end()) && hSelected!=it->hParent;
    it++);

CString Hierarchy = LookupHierarchy(it->hParent);

      

Important After activating the setting, you need to delete the precompiled header cache file (* .pch) as it has no effect.

+6


source







All Articles