I cant put a string in a switch nor an array in a class

Posted by TimothyTech on Stack Overflow See other posts from Stack Overflow or by TimothyTech
Published on 2010-06-17T16:57:57Z Indexed on 2010/06/17 17:13 UTC
Read the original article Hit count: 143

Filed under:
|
|

Okay, im making a pretty big file in my opinion, so i wanted to separate it into several files for cleaner code. so i have my main .cpp file and two header files holding my classes. well the header files dont hold strings, it aboslutely wont budge. i call the library in both my .cpp file and even tried it in my header file.

another issue i ran into is using strings to make switches function, reason being if i use integers in a switch if the user inputs a alphabetical character the program goes into an endless loop.

string choice;

switch (choice)
{

  case "1" : 
  //... 
  break;
  case "2" : 
  //... 
  break;
}

and my last issue is when i create an object in a case it gives an error. says cross initialization of object.

string choice;

switch (choice)
{

  case "1" : 
  Class object; 
  break;
  case "2" : 
  //... 
  break;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about class