Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed Help Using "Sort" Within My Program
    text
    copied!<p>I have a simple program that lists input in order of precedence, checking only for operators and ranking them like so, "*/+-":</p> <pre><code>#include &lt;iostream&gt; #include &lt;stack&gt; #include &lt;string&gt; using namespace std; int prec(char op) { if (op == '*' || op == '/') return 0; return 1; } bool compareprec(char a, char b) { return prec(a) &lt; prec(b); } int main() { char input[] = "+-/*"; cin &gt;&gt; input; sort(input, input + 4, &amp;compareprec); cout &lt;&lt; input; } </code></pre> <p>I'm trying to implement it within a more complex program that uses stacks to check alpha numerical input and do an infix to postfix conversion, ranking something that looks like this: "9*9+9" into "9 9 9 * +". The more complex program is as follows:</p> <pre><code>#include &lt;iostream&gt; #include &lt;stack&gt; #include &lt;string&gt; using namespace std; int prec(char op) { if (op == '*' || op == '/' || op == '+' || op == '-') return 0; return 1; } bool compareprec(char a, char b) { return prec(a) &lt; prec(b); } int main() { stack&lt;char&gt; s; char input; while (cin.get(input) &amp;&amp; input != '\n') { if (isalnum(input)) cout &lt;&lt; input &lt;&lt; " "; else if (input == '(') s.push(input); else if (input == ')') { while (!s.empty() &amp;&amp; s.top() != '(') { cout &lt;&lt; s.top() &lt;&lt; " "; s.pop(); } if(!s.empty()) s.pop(); else cout &lt;&lt; "ERROR: No Matching ( \n"; } else if (s.empty() &amp;&amp; input == '*'|| input == '/'|| input == '+'|| input == '-') { sort(input, input + 4, &amp;compareprec); // Error Begins Here? s.push(input); } else if (input == '*'||input == '/'||input == '+'|| input =='-') while (!s.empty()) { sort(input, input + 4, &amp;compareprec); // More Errors Here? cout &lt;&lt; s.top() &lt;&lt; "\n "; s.pop(); s.push(input); } } while (!s.empty()) { cout &lt;&lt; s.top() &lt;&lt; " "; s.pop(); } } </code></pre> <p>But I keep getting an error that says:</p> <pre><code>error: no matching function for call to 'sort(char&amp;, int, bool (*)(char, char))' error: no matching function for call to 'sort(char&amp;, int, bool (*)(char, char))' </code></pre> <p>And I'm not sure why. I know it's probably something painfully obvious/silly but I can't figure it out. Any help would be appreciated. Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload