The code in its current form works just fine. But whenever I enable the commented out portion for the unary operators there is a segmentation fault at runtime.
if (in>>opt)
{
opn = stack.back();
stack.pop_back(); //1
switch (opt)
{
case'p':{opn += stack.back(); break;}
case'm':{opn=stack.back()-opn; break;}
case'*':{opn *= stack.back(); break;}
case'/':{opn=stack.back()/opn; break;}
default:
{}
}
stack.pop_back(); //2
stack.push_back(opn);
}
//......................... Unary operator
// in.clear();
// opn=stack.back();
// stack.pop_back(); //3
// if(in>>opt_s)
// {
// if(opt_s=="sin")stack.push_back(sin(opn));
// }
///This BLOCK is NOT working as it should...Wonder Why ? :(
//.....................................
Every operator has a number of arguments. That is the numbers of pop_back that you should perform.
But in the case of an unary operator you are trying to perform 3 pop_backs.