错误:';'、',' 或 ')' 在 '&' 之前令牌 [英] error: expected ';', ',' or ')' before '&' token
问题描述
void cargarProducto (Producto &p)
{
printf("\nIngrese el c¢diqo: ");
scanf("%d", &p.codigo);
fflush(stdin);
printf("\nIngrese la descripci¢n: ");
int i;
printf("\nIngrese 1 si es importado");
scanf("%d", &i);
if(i == 1)
{
p.discriminante = IMPORTADO;
}
else
{
p.discriminante = LOCAL;
}
if(p.discriminante == IMPORTADO)
{
printf ("\nIngrese al origen:");
scanf("%c", &p.origen);
}
else
{
printf ("\nIngrese el telefono");
scanf ("%d", &p.impoExpo.telefono);
}
}
在行中 void cargarProducto (Producto &p) 抛出以下错误:error: expected ';', ',' or ')' before '&'令牌
In the line void cargarProducto (Producto &p) throws the following error: error: expected ';', ',' or ')' before '&' token
void copiar (Producto &destino, Producto origen)
{
destino.codigo=origen.codigo;
destino.descripcion=origen.descripcion;
destino.unidadMedida=origen.unidadMedida;
destino.precio=origen.precio;
destino.discriminante.origen.discriminante;
if (destino.discriminante ==IMPORTADO)
{
destino.impoExpo.origen=origen.impoExpo.origen;
}
else
{
impoExpo.telefono=origen.impoExpo.telefono;
}
}
同样的 in the line void copiar (Producto &destino, Producto origen)
The same in the line void copiar (Producto &destino, Producto origen)
推荐答案
如果你的意图是让copiar
直接修改destino
,你必须传递目的地
.C 中不存在按引用传递.
If your intention is to have copiar
directly modify destino
, you must pass the address of destino
. Passing by reference doesn't exist in C.
void copiar (Producto * const destino, const Producto * const origen)
{
destino->codigo = origen->codigo;
destino->descripcion = origen->descripcion;
destino->unidadMedida = origen->unidadMedida;
destino->precio = origen->precio;
destino->discriminante = origen->discriminante;
if(destino->discriminante == IMPORTADO)
destino->impoExpo.origen = origen->impoExpo.origen;
else
impoExpo->telefono = origen->impoExpo.telefono;
}
最好按地址传递结构,即使您不打算修改它们的内容.这是因为结构可能很大,如果不需要,您不想将它们放在堆栈中.在需要的地方声明结构 const
.上面代码中,destino
的地址是常量,不是数据;对于origen
,地址和数据都是常量.
It's better to pass structures by address, even if you don't plan on modifying their contents. This is because structures may be large and you don't want to put them on the stack if not needed. Declare structures const
where needed. In the above code, the address of destino
is constant, but not the data; for origen
, both the address and data are constant.
这篇关于错误:';'、',' 或 ')' 在 '&' 之前令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!