defualt and user constructors

I'm having issues with what a default constructor is and how to write it as code.
This code im going to show you is my attempt at simply defining player, point, bullet as a class.
I need to Modify the classes to include the following.

A default constructor

User defined constructor

I have checked online and i think i might already have a default constructor but i'd really like some tips and guidance as to how to modify the classes to include those two things.

Thanks.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  #include <iostream>

using namespace std;

class BulletClass{
public:
   BulletClass(string z){
    setColour(z);
   }
    void setColour(string x){
        Colour =x;
    }
    string getColour(){
    return Colour;
    }

private:
    string Colour;

};
class PlayerClass{
public:
    PlayerClass(int z){
    setHealth(z);
    }
    int setHealth(int x){
        Health = x;

    }
    int getHealth(){
        return Health;
    }

private:
    int Health;
};


int main()
{

    BulletClass bulletobject("Bullet black");
    std::cout <<bulletobject.getColour()<< endl;
    std::cout <<"Player ";
    PlayerClass playerobject(100);
    std::cout <<playerobject.getHealth()<<endl;
    return 0;
}
Examples of default constructor for Player class:
1
2
3
4
5
6
7
8
9
10
11
//Direct setting default value:
PlayerClass()
{
    setHealth(100);
}

//Delegating to the parametrized constructor:
PlayerClass() : PlayerClass(100) {}

//Using default value (modify user constructor):
PlayerClass(int z = 100)
closed account (j3Rz8vqX)
The purpose of a default constructor is to ensure there is no error, if no arguments are passed.

As MiiNiPaa illustrated on line(2-5):

---What happens if they/you construct an object like this:BulletClass bulletobject();

As for a "User defined constructor", you've already implemented one:
PlayerClass(int z)
Topic archived. No new replies allowed.