Thread: ISO C++ Forbids it!

  1. #1
    Join Date
    Jul 2005
    Manchester, England

    ISO C++ Forbids it!

    Program wont compile because of a:
    Comparison between pointer and integer
    Can this program be saved? Is it badly written? I'm only new, so any help's much appreciated.

    ( I should probably comment my code - But, sometimes I comment not enough, sometimes I comment too much. On larger programs I comment, but on smaller ones, I think when left un-commented, they look nicer )

    class operate{
                 char oper;
                 int w;
                 int x;
                 int recognize(char opr, int y, int z);
                 int add(int y, int z);
                 int multiply(int y, int z);
                 int divide(int y, int z);
    int operate::add(int y, int z){
        return y + z;
    int operate::multiply(int y, int z){
        return y * z;
    int operate::divide(int y, int z){
        return y / z;
    int operate::recognize(char opr, int y, int z){
        if ( opr == "+" ){
             return add(y,z);
        else if (opr == "*" ){
             return multiply(y,z);
        else if (opr == "/" ){
             return divide(y,z);
        else {
             return 0;
    int main(){
        try {
            operate calculator;
            cout << ">>>";
            cin >> calculator.w;
            cout << ">>>";
            cin >> calculator.oper;
            cout << ">>>";
            cin >> calculator.x;
            cout << calculator.recognize(calculator.oper, calculator.w, calculator.x);
        catch (...) {
              cout << "Default error. " << endl;
    Last edited by Jimmey; 12-05-2005 at 04:48 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    opr == "+"
    opr is a single char and "+" is a string.
    You need to use
    opr == '+'

  3. #3
    Join Date
    Jul 2005
    Manchester, England
    Thanks -
    Sorry to post so much code for such a simple mistake

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    main() should return a value (but it doesn't have to; 0 is returned implicitly).

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 01-09-2006, 06:17 AM
  2. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 05:20 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Replies: 1
    Last Post: 11-06-2003, 07:05 PM
  5. ISO C++ forbids declaration of
    By bhorrobi in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2003, 02:36 PM
Website Security Test