error class " " has no member function named " "

hey guys i need help....say i have a class bullet and in dat class i define a variable called attack_damage in bullet.h within public and i create an object in main called bullet1.... so is it wrong for me to access dat variable like shown below in the code and if not how can i access it....thanx in advance

1
2
3
4
5
6
7
 
// bullet.h
  bool attack damage=false; 

// creating object in main 
bullet bullet1; 
bullet1.attack_damage=true;
You can make attack_damage public, or you can add getter and setter functions to the class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Bullet
{
public:
	int get_attack_damage() const
	{
		return attack_damage;
	}
	void set_attack_damage(int new_attack_damage)
	{
		attack_damage = new_attack_damage;
	}
private:
	int attack_damage;
};
Last edited on
thanx for de reply il do just dat
Topic archived. No new replies allowed.