#include "stdafx.h"
#include <string.h>
void Get(char* &psz)
{
memcpy(psz, "xxxx", 4);
}
int main(int argc, char* argv[])
{
printf("Hello World!\n"); char szName[32] = {0};
char *p = szName;
Get(szName);
Get(p);
printf(szName);
getchar();
return 0;
}
D:\QF_TEMP\xxx\xxx.cpp(16) : error C2664: 'Get' : cannot convert parameter 1 from 'char [32]' to 'char *& '
        A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing cl.exe.

解决方案 »

  1.   

    void Get(char* &psz)
    {
    memcpy(psz, "xxxx", 4);
    }把参数里的“&”去掉,再编译就没问题了
      

  2.   

    char *&是啥意思?char *& a = char a?
      

  3.   

    void Get(char* &psz)指针是不可以为引用的.引用本身的一定意义上是为了代替指针来改值的(我不是说引用就是为了代替指针,请大家不要在这个问题上讨论).直接 void Get(char* psz) 这样就可以了
      

  4.   

    void Get(char* &psz)  //要么用* 要么用引用,一般情况下~ 只能用一个
      

  5.   

    void Get(char* &psz)是vc.net里的东东,即对char的指针变量的引用,在vc6.0中不合法