STL iterator conversions in VC.NET

  • Thread starter Thread starter Dr. Proton
  • Start date Start date
D

Dr. Proton

Hi!
I just moved from VC++ 6.0 to VS.NET and my project no longer compiles
properly. Why this doesn't work anymore (I get C2679 error):
 
Dr. Proton said:
Hi!
I just moved from VC++ 6.0 to VS.NET and my project no longer compiles
properly. Why this doesn't work anymore (I get C2679 error):

---
std::vector<int> intVec;
int *p;

p = intVec.begin(); // C2679

intVec.begin() returns a 'std::vector<int>::iterator', not a 'int *' .
 
Edward said:
intVec.begin() returns a 'std::vector<int>::iterator', not a 'int *' .

Right, and there never was a guarantee that vector<T>::iterator is the same
as T*, though it was T* in VC6. There's a simple, portable workaround:

p = &*intVec.begin();
 
Right, and there never was a guarantee that vector<T>::iterator is the same
as T*, though it was T* in VC6. There's a simple, portable workaround:

p = &*intVec.begin();

Thanks for the info! It compiles fine now.
 
Back
Top