Share via


Standard C++ Library Changes: Visual C++ .NET 2003

If you are upgrading a program that uses Standard C++ Library code that compiled in Visual C++ 6.0, you should be aware of the following issues:

  • reverse_iterator Changes

  • Some Iterators Are No Longer the Same as Pointers

  • MIN/MAX #define Change

reverse_iterator Changes

The names for some of the types defined by the Standard C++ Library reverse_iterator class have changed. Also, there are different template arguments for this class.

The following sample compiled in Visual C++ 6.0, but fails in the current version:

#include <iterator>
#include <vector>
typedef std::iterator<std::random_access_iterator_tag, char, int> random_it;

int main( )
{
   char c;
   
   // too many template args for VC7
   typedef std::reverse_iterator< random_it, char, char&, char *, int > rev_it; 
   rev_it::reference_type x = c;
   rev_it::pointer_type y = 0;
   rev_it::iter_type z;

   /*
   // try the following code instead
   typedef std::reverse_iterator< random_it > rev_it;
   rev_it::reference a = c;
   rev_it::pointer b = 0;
   rev_it::iterator_type c1;
   */
}

Some Iterators Are No Longer the Same as Pointers

In some Standard C++ Library classes, iterators are no longer defined as pointer types.

The following sample compiled in Visual C++ 6.0, but fails on the indicated lines in the current version:

#include <string>
#include <vector>
#include <algorithm>

bool pred(int i) { 
   return true; 
};

int main()
{
   std::string str("test");
   const char *pszstr = str.begin();       // LINE 8: INCORRECT
   const char *pszStr2 = str.c_str();      // OK
   const char *pszStr3 = &(*str.begin());  // OK

   std::vector<int> v;
   int *pint = std::remove_if(v.begin(), v.end(), pred);   // LINE 13: INCORRECT
   std::vector<int>::iterator iint = std::remove_if(v.begin(), v.end(), pred);   // OK
}

MIN/MAX #define Change

The Standard C++ Library definition of _MIN and _MAX changed from:

#define _MAX   _cpp_max
#define _MIN   _cpp_min

to:

#define _MAX   (max)
#define _MIN   (min)

This makes definitions of std::_MIN invalid.

The following sample compiled in Visual C++ 6.0, but fails on the indicated line in the current version:

#include <xutility>
#include <stdlib.h>
using namespace std;
int main()
{
   std::_MAX(3,4);   // error
   _MAX(4,5);
}

See Also

Concepts

Standard C++ Library Changes