Reputation: 8808
I'm getting said error on this line "b = true". Now Why am I getting this error? Aren't I pointing to TurnMeOn and thus saying TurnMeOn = true?
class B{
void turnOn(bool *b){b = true}
};
int main(){
B *b = new B();
bool turnMeOn = false;
b->turnOn(&turnMeOn);
cout << "b = " << turnMeOn << endl;
}
Upvotes: 1
Views: 10520
Reputation: 2912
turnOn
requires a pointer to bool as parameter. You're using it as an actual bool
. I guess you're looking for a reference, i.e. bool& b
as parameter declaration in your method.
Upvotes: 5
Reputation: 258228
No. As you've written it, it would need to be *b = true
.
Alternatively, you could write the function to take a reference to a bool, so that
void turnOn(bool &b) { b = true; }
would be correct.
Upvotes: 4