我试图将一个地址的值存储在非指针类型的整型变量中,但是当我尝试进行类型转换时,编译器报错“从'int*'到'int'的无效转换”。这是我正在使用的代码:
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
vector<int> test;
int main() {
int *ip;
int pointervalue = 50;
int thatvalue = 1;
ip = &pointervalue;
thatvalue = ip;
cout << ip << endl;
test.push_back(thatvalue);
cout << test[0] << endl;
return 0;
}
uintptr_t
),你可能想要对结果进行的任何算术运算都可以使用指针更容易地完成,甚至更不易于移植。 - user395760