Gcc: Cruza la inicialización de …
buf … hasta que uno se acostumbra a todos los errores y advertencias que te suelta gcc pasa mucho tiempo, y es que acaba de darme uno de esos errores que no sabes que solución puede tener, ya que la solución dista mucho de lo que uno podría imaginarse en un principio. El error que me daba era algo como esto dentro de un case de un bloque switch:
../src/octree.tcc:833: error: salto a la etiqueta case ../src/octree.tcc:823: error: cruza la inicialización de ‘const guoctree::Octree<guoctree::octreeValues, 1>::Aggregate* aa’
Si te ha ocurrido algo como esto alguna vez sigue leyendo para averiguar como solucionar el problema.
La razón es que hay una declaración de un objeto o variable sin ámbito (sccope). Por lo tanto, el ámbito del objeto podría atravesar la sentencia break y aplicarse al siguiente case. Esto generalmente se da cuando inicializamos algún objeto mediante su constructor y no delimitamos cada case con llaves o brackets. Por lo tanto la solución es bien sencilla os dejo a continución mi trozo de código que fallaba:
case AggregateNode:
const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
if (a->value(0,0,0) == OV_BLACK)
{
out << "Shape { \n"
<< "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
<< "geometry Box { size 1.0 1.0 1.0 }\n"
<< "},\n";
}
break;
Y ahora el misco trozo de código corregido (delimitado por llaves):
case AggregateNode:
{
const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
if (a->value(0,0,0) == OV_BLACK)
{
out << "Shape { \n"
<< "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
<< "geometry Box { size 1.0 1.0 1.0 }\n"
<< "},\n";
}
}
break;
Por lo tanto os aconsejo que os acostumbréis a escribir vuestros bloques de código switch con brackets siempre que os acordéis ;-).
buf … Until you get used to all errors and warnings that gcc throw, much time is spent. Recently gcc show me one of this errors with difficult explanation, and its solution are far from one could imagine in first instance. The error which gcc show me about a line code inside a switch block code is:
../src/octree.tcc:833: error: jump to case label ../src/octree.tcc:823: error: crosses initialization of ‘const guoctree::Octree<guoctree::octreeValues, 1>::Aggregate* aa’
If you ever had some error like this, continue reading this post to find out how to solve the problem.
The reason for this problem is that there is a declaration of an object or variable without scope. Thus, the scope of the object could traverse the break statement and apply to the next case. This case appears generally when we initialize some object through its constructor and don’t delimit each case statement with brackets. Therefore the solution is very easy, we only must enclose all the cases whit brackets to avoid problems. Now, you can see the wrong code below:
case AggregateNode:
const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
if (a->value(0,0,0) == OV_BLACK)
{
out << "Shape { \n"
<< "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
<< "geometry Box { size 1.0 1.0 1.0 }\n"
<< "},\n";
}
break;
And after applying the solution this is the code:
case AggregateNode:
{
const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
if (a->value(0,0,0) == OV_BLACK)
{
out << "Shape { \n"
<< "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
<< "geometry Box { size 1.0 1.0 1.0 }\n"
<< "},\n";
}
}
break;
I suggest that you get used to write all case statements with brackets
.
loading...





loading...
Muchas gracias, me ha sido de gran ayuda!!
Un saludo.
loading...
Grande, me solucionaste, hace media hora que estoy trabad en eso, gracias!!!!
loading...
Ahhhhh gracias, yo llevaba ya 1 hora, y no creo q hubiera podido resolverlo por mi, gracias
loading...
Gracias…. me sacaste de un gran apuro tenia como dos horas con este error….
loading...
Joooder, muuuuchas graciass!!! desde luego….no se me olvidarán nunca más las llaves…jeje. Saludoss