Help with OOP branching

What I'm trying to do is take a class member and branch using an if statement based on that variable. In this case, the variable name is hostile and I am trying to see whether the NPC 'dave' is hostile. I've looked around using Google and found nothing as well as on the documentation for this site and so I turn to the forums. Please help. I've tried to work out how to do it in the code below but unsurprisingly, I was unable to work it out, can anyone give me a hand?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class NPC
{
private:
int health , damage , speed , relationship ;
string inventory ;
bool hostile ;

public:
void setHealth (int hp) { health = hp ; }
void setDamage (int dp) { damage = dp ; }
void setSpeed (int sp) { speed = sp ; }
void setRelationship  (int rp) { relationship = rp ; }
void setHostile (bool hos) { hostile = hos ; }

int getHealth() { return health ; }
int getDamage() { return damage ; }
int getSpeed() { return speed ; }
int getRelationship() { return relationship ; }
bool getHostile() { return hostile ; }
} dave , nick , boris , barry ;

int main() {
dave.setHostile( false ) ;
if ( dave.hostile = true ) {
cout << "Dave smacks you in yo face" << endl ;
}
else {
cout << "Dave gives you a lovely hug. Awww!" << endl ;
}

return 0 ;
}
I'm getting a sense of deja vu here. My first reply disappeared, so a quick summary:

use == rather than = at line 24

call the function getHostile() rather than access the variable hostile directly

use simply if ( dave.getHostile() ) rather than if ( dave.getHostile() == true)
@Chervil
You sir are a scholar and a gentleman; I was completely lost. The reason your reply disappeared before is that I never saw it before I deleted the thread after finding what I thought was the solution but turned out to be a dead end. Thank you so much!
@JLBorges
I bow to your superior wisdom, I was basing the functions off a book which I used for reference.
Topic archived. No new replies allowed.