Hi there, I do program in C for about 2 years, but only now I am doing some C++ coding, and using Classes, etc. I found C++ a LOT more powerful then C, but I am having a litle problem with THIS code (that is inside the main funcion, and with user input handling cut out):
//*****************
if (option)
{
cout << "1) Enter the year" << endl;
cin >> c_year;
cout << "2) Enter the chassis number" << endl;
cin >> c_chassis;
Car first_one = (c_year, c_chassis);
} // end of if (option)
//***********
then, in the end of the main funcion, when I try to cout any of the the first_one Car object values, the compiler (MS Visual C++ 6) gives me and error message that says: "first_one: undeclared identifier".
So my question is: can't I declare an Object inside an IF statement? Why not? Is the IF statement really a funcion and when it ends the first_car got out of scope? Or is it something else? PLEASE HELP =]
//*****************
if (option)
{
cout << "1) Enter the year" << endl;
cin >> c_year;
cout << "2) Enter the chassis number" << endl;
cin >> c_chassis;
Car first_one = (c_year, c_chassis);
} // end of if (option)
//***********
then, in the end of the main funcion, when I try to cout any of the the first_one Car object values, the compiler (MS Visual C++ 6) gives me and error message that says: "first_one: undeclared identifier".
So my question is: can't I declare an Object inside an IF statement? Why not? Is the IF statement really a funcion and when it ends the first_car got out of scope? Or is it something else? PLEASE HELP =]