-5

I've been searching for a while on why this does not work. I have not gotten a clear answer.

Can anyone explain why trying to access this boolean variable and comparing it to another boolean variable won't work?

I also tried setting the rhs of the comparison to 0, and that got rid of the boolean/int error, but I'm still getting the error.

#include <iostream>

using namespace std;

class MyClass {
public:
    MyClass() {
        setWorking(true);
    }

    //Mutator
    void setWorking(bool x) { working = x; }

    //Accessor
    bool getWorking() { return working; }

private:
    bool working;
};

int main() {

    MyClass alpha;

    if (alpha.getWorking == true) {
        cout << "its working\n";
    }
    else {
        cout << "not working\n";
    }

    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

1

In main function

if (alpha.getWorking == true)

should be

if (alpha.getWorking())
Yousaf
  • 27,861
  • 6
  • 44
  • 69