423,323 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,323 IT Pros & Developers. It's quick & easy.

Error passing strings and char to bool function

P: 1
for(unsigned x = 0; x < infix.length(); ++x)
{
// place numbers (standard, decimal, & negative)
// numbers onto the 'postfix' string
if((isdigit(infix[x])) || (infix[x] == '.'))
{
postfix += infix[x];
}

else if ((infix[x] == '-'))
{
if(checkfornegative(infix[x], infix)== 1))// error: expected primary-expression before ) token
else if(checkfornegative(infix[x], infix)== 0))
{
postfix+= " ";
}
else if(checkfornegative(infix[x], infix)== 0))// same error as above
{
postfix += infix[x];
}

}


// this is my bool equation
bool checkfornegative(char C, string& QQ)
{
bool status;
if((C == '-') && (QQ[C+1] == ' '))
{
status = true;
}
else if((C == '-') && (QQ[C+1] != ' '))
{
status = false;
}
return status;
}
Oct 6 '17 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,163
Your bool function requires:

Expand|Select|Wrap|Line Numbers
  1. bool checkfornegative(char C, string& QQ);
Here you pass:

Expand|Select|Wrap|Line Numbers
  1. checkfornegative(infix[x],infix)
I assume infix[x] is a char but is infix a C++ string&??

I suspect infix is a char string and not a C++ string object.

In order to use a string& you have to pass in a C++ string object. If you can't do that then the compiler needs to create a string for your function. In this case the argument should be string and not string&.

So do you have:

Expand|Select|Wrap|Line Numbers
  1. string infix;  //C++ string object
  2.  
  3.  
or

Expand|Select|Wrap|Line Numbers
  1. char infix[some number]; //array of char
Oct 7 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.