why i cant instantiate objects inside a switch-case block

前端 未结 3 796
无人及你
无人及你 2021-02-15 12:36

my code has 3 classes n_hexa,n_octa,n_bin. The code is here

switch(choice)
{
case 1: cin>>n; 
 n_hexa nx(n);
        break;
case 2: cin>>n; 
 n_octa          


        
3条回答
  •  孤独总比滥情好
    2021-02-15 12:54

    Try declaring the variables above the switch command:

    n_hexa nx;
    n_octa no;
    n_bin nb;
    switch(choice) {
        case 1:
            cin>>n;
            nx(n);
            break;
    ...
    

提交回复
热议问题