Argument passing by reference to pointer problem
问题 Every time I try to compile my code I get error: cannot convert parameter 1 from 'int *' to 'int *&' The test code looks like this: void set (int *&val){ *val = 10; } int main(){ int myVal; int *pMyVal = new int; set(&myVal); // <- this causes trouble set(pMyVal); // <- however, this doesn't } I'd like to call that function in a single shot without creating a pointer somewhere only to pass it. And as pointers don't have constructors, something like this can't be done: set(int*(&myVal)); Is