class composition issue

hi, i took this example from a previous post of another user.. whe i try to run it i get a compile error saying : "default argument missing for parameter 2 of People "... line 19.. I dont understand why const Birthday& b is not a valid argument. any help appreciated. 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
    #include <iostream>
    #include <string>
    using namespace std;
    
    class Birthday
    {
        public:
            Birthday(int d=1,int m=1,int y=1900) : day(d),month(m),year(y) {}; // constructor
            Birthday(const Birthday& other) // copy contructor
            {
                day=other.day;
                month=other.month;
                year=other.year;
            }
        private:
            int day;
            int month;
            int year;
    };
    class People
    {
        public:
            People(string n="", const Birthday& b) : name(n),dob(b) {}; // constructor
        private:
            string name;
            Birthday dob;
    };
Last edited on
try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Birthday
{
public:
	Birthday(int d = 1, int m = 1, int y = 1900) : day(d), month(m), year(y) {}; // constructor
	Birthday(const Birthday& other) // copy contructor
	{
		day = other.day;
		month = other.month;
		year = other.year;
	}
private:
	int day;
	int month;
	int year;
};
class People
{
public:
	People(string n = "", const Birthday& b = Birthday()) : name(n), dob(b) {}; // constructor
private:
	string name;
	Birthday dob;
};
thanks, that did the trick!
Topic archived. No new replies allowed.