On 12 avr, 13:26, Rahul <sam_...@yahoo.co.inwrote:
I have the following code,
class A
{
public : A()
{
}
void show()
{
}
};
int main()
{
cout<<"Enter the number : ";
int n;
cin>>n;
if(n<10)
goto label;
A obj;
label:
obj.show();
return(0);
}
and i get the expected error saying "initialization of obj is
skipped by goto label". But when i remove the definition of
the constructor from the class, i don't the error, why is this
so?
Because you're declaring an uninitialized object, and
presumably, your code is capable of handling uninitialized
objects. (In this regard, an object is "initialized" if there
is explicit initialization, or the type of the object has a
non-trivial constructor.)
In real code (which doesn't use goto), this is still relevant in
switch statements, whose semantics is exactly that of a goto.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34