In below program both if statements gives an error #include<iostream> #include<conio.h> using namespace std; class operation { int bank_id,balance; public: int input() { cout<<"enter the bank_id "; cin>>bank_id; cout<<"enter the balance "; cin>>balance; } operation operator ==(operation p) { operation b1,b2; b1.bank_id=bank_id+p.bank_id; b1.balance=balance+p.balance; b2.bank_id=bank_id+p.bank_id; b2.balance=balance+p.balance; if(b1==b2) { return b1; } else { return b2; } } operation operator++() { operation d1; d1.bank_id=bank_id+10; d1.balance=balance; return d1; } operation operator--() { operation d2; d2.bank_id=bank_id; d2.balance=balance-10; return d2; } int display() { cout<<"the bank_id is ::"<<bank_id; cout<<"the balance is ::"<<balance; } }; int main() { operation ban1,ban2,res1,res2; ban1.input(); ban2.input(); if(ban1==ban2) { res1=++ban1; res1.display(); } else { res2=--ban2; res2.display(); } }

If you read replies about badly formed posts, you find out why you must take a minute to fix a post like this. In short, unreadable.

What is the intent of this program? What specific error are you getting? What are you doing when the error appears? Is it a compile error or a run-time error? Which if statements generate this error; you have more than 2.

Please enclose code samples in a code block. On this forum that is done by clicking the third button on the toolbar just above the edit area. Let's see; this should not be that difficult to format.

#include<iostream>
#include<conio.h>

using namespace std;
class operation {
    int bank_id,balance;

public: 
    int input() { 
        cout<<"enter the bank_id ";
        cin>>bank_id; 
        cout<<"enter the balance ";
        cin>>balance;
    }

    operation operator ==(operation p) {
        operation b1,b2;

        b1.bank_id=bank_id+p.bank_id; 
        b1.balance=balance+p.balance;
        b2.bank_id=bank_id+p.bank_id;
        b2.balance=balance+p.balance;
        if(b1==b2) {
            return b1;
        } else {
            return b2;
        }
    }

    operation operator++() {
        operation d1;

        d1.bank_id=bank_id+10;
        d1.balance=balance;
        return d1;
    }

    operation operator--() {
        operation d2;

        d2.bank_id=bank_id;
        d2.balance=balance-10;
        return d2;
    }

    int display() {
        cout << "the bank_id is " << bank_id;
        cout << "the balance is " << balance;
    }
}; 

int main() {
    operation ban1,ban2,res1,res2;

    ban1.input();
    ban2.input(); 
    if (ban1 == ban2) {
        res1 = ++ban1;
        res1.display(); 
    } else {
        res2 = --ban2;
        res2.display(); 
    }
}

You equality operation looks more like an addition operation. Comparison operators like equality (==) tend to return bool to say if the relationship between the objects holds or not.

Put spaces around your operators to make them easier to read; I have done this in main().

Edit: Ah, I see it now. The if() parameters are expected to be bool. You have defined the equality operator to return operation instead. The compiler does not know how to convert operation to bool so does not know how to proceed. You need to revisit the definition of your class methods.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.