#include <iostream>
using namespace std;
void reference(int &ref){
cout << ref << endl;
}
void pointer(int *ref){
cout << *ref << endl;
}
int main(){
int *i = new int[1];
*i = 10;
reference(*i); // fine
reference(i); // why not compiling!!! why not referencing to my pointer??
pointer(i); // fine
}
我想引用一个指针,因为我可以看到我被允许引用值而不是指针,为什么?为什么我们不能引用指针,而是值
那么你可以:void指针(int *&ref){'。这是有点不清楚你实际上要求什么。 – 2014-11-01 08:15:44
它不会崩溃,这是一个编译错误。 – 2014-11-01 08:20:06
但为什么反对,似乎有效的问题? – 2014-11-01 08:45:30