Hi , this pr. works with clases but someway it just throws me a error:

``````switch (atoi(i))//yes its an int 1,2,3,... etc...
{
case 1:
R S(r, h);//create new class R object named S,to constructor we give two     parameters
F * f1 = &S; //yess pointers polymorph....
cout << "V = pr^2*h: " << fig1->t() << " m^3" << endl;
cout << "S=pr^2...: " << fig1->p() << " m^2" << endl;
cout << endl;
break;
case 2://errorrr... so why & how to fix it
//error : crosses initialization of R``````

I'd be really happy if you could help me to solve this quickly :)

2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Onixtender

Hi , this pr. works with clases but someway it just throws me a error:

``````switch (atoi(i))//yes its an int 1,2,3,... etc...
{
case 1:
R S(r, h);//create new class R object named S,to constructor we give two     parameters
F * f1 = &S; //yess pointers polymorph....
cout << "V = pr^2*h: " << fig1->t() << " m^3" << endl;
cout << "S=pr^2...: " << fig1->p() << " m^2" << endl;
cout << endl;
break;
case 2://errorrr... so why & how to fix it
//error : crosses initialization of R``````

I'd be really happy if you could help me to solve this quickly

1. This is C++ code (such as it is). There are much better string to int conversions available than atoi

2. Use some more { }, like this

``````switch (atoi(i))//yes its an int 1,2,3,... etc...
{
case 1:
[B]{[/B]
R S(r, h);//create new class R object named S,to constructor we give two     parameters
F * f1 = &S; //yess pointers polymorph....
cout << "V = pr^2*h: " << fig1->t() << " m^3" << endl;
cout << "S=pr^2...: " << fig1->p() << " m^2" << endl;
cout << endl;
[B]}[/B]
break;``````