奇怪,vector的iterator不能有指针的用法 "->" ??
nbb 2003-10-08 07:36:30 #include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
class Struct1{
public:
int a;
char * b;
Struct1(): a(0),b(0){} //初始化为0
};
class Vec1{
public:
typedef std::vector<Struct1> Arraytp;
Arraytp array;
Arraytp::iterator it;
Vec1(){
array.push_back(Struct1());
array.push_back(Struct1());
it=array.begin();
}
char* test(char* p1){
return p1-
(it->b); //故意分成两行来写,编译时指示这里有错: C2440
}
};
int _tmain(int argc, _TCHAR* argv[])
{
char* pa=(char*)0x10000000;
Vec1 ary;
char* pc=ary.test(pa);
cout<<"char* pc="<<(long)pc<<endl;
return 0;
}
//错误原因: C2440
//k:\sztst.cpp(30) : error C2440: “return” : 无法从“__w64 int”转换为“char *”
//试过reinterpret_cast、C 样式转换也无效,还是C2440, 什么原因????