Constructor only running when passed value

Hello Cplusplus.com! I am working on a simple zoo simulation program to work on my knowledge of classes, and even though I am only a few lines in, I already have a big problem. For my zoo class, the constructor only runs when passed a value.
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// bears lions zebras gorrilas monkeys, oh my!
// A zoo class program using classes (duh) and
// inharitance
#include <iostream>
#include <string>

using namespace std;

string animalTypes[10]=
{
    "Tiger",
    "Elephant",
    "", // have not come up with the rest of the animals yet, but 
    "", // irrelevant to this problem
    "",
    "",
    "",
    "",
    "",
};

class Animal
{
public:
    string name;
    Animal(int n_type); // the constructer
protected:
    int hunger;
    bool sick;
    int age;
    int type; // this will be a number that will be used in animalType. i.e. a tiger would be 0
    string nameoftype;
};

Animal::Animal(int n_type)
{
    cout << "What would you like to name this " << animalTypes[n_type] << "?\n";
    cin >> name;
    system("cls");

    age = 0;
    type = n_type;
    nameoftype = animalTypes[n_type];

    cout << "The animal " << name << " of type " << nameoftype << " has been created\n";
    system("pause");
    system("cls");
}

class Zoo
{
public:
    string name;
    Zoo(int a);
    int money;
    int moneyGoal;

private:
    int nAnimals;
    int maxAnimals;
};

Zoo::Zoo(int a)
{
    cout << "Welcome to the Virtual Zoo Simulation! In this quasi-game, you must\n";
    cout << "raise and take care of various zoo animals in order to sell them to other\n";
    cout << "zoos and make money! You start with $300 dollers. Try to make $10,000!\n";
    cout << "Have fun!\n";
    moneyGoal = 10000;
    maxAnimals = 25;
}

int main()
{
    Zoo myzoo(0);
    /* stuff not needed right now
    
    Animal *Animals[25]={};
    string stripes = "Stripes";
    Animals[0] = new Animal(0);

    cout << "Everyone welcome " << Animals[0]->name << " to the zoo!\n";

    delete Animals[0];
    cout << "Stripes has been deleted!";
    */
    return 0;
}


The constructor is on line 63. When I don't have a value passed to it, it does not show the introduction, apparently not running. However, as soon as I passed a value to it to test something, it ran. My friend who is a bit better at programming than me said that the thing he can think of is that I have more than one constructor. What do y'all think?
Last edited on
You only have one Zoo constructor and the program would not compile if you did not pass a value in line 75.
But if I had to guess, you probably wrote this: Zoo myzoo();
That's not an object instantiation, but a function declaration of a function myzoo that returns a Zoo object and takes no parameters.
So I should try Zoo myzoo() instead, missing the ;?
No, Zoo myzoo; would be the correct variant if you want to call the standard constructor.
Thank you! I was just being stupid I guess.
Topic archived. No new replies allowed.