Composition example error

I am trying to make a program which the user types the current date, user's name and birthday then the program calculates the age using 2 different classes
whenever I try to run the project I get an error saying "no matching functions for call to 'class1::age()' " in line 15 in class2.cpp.
class1 is for calculating the age, class 2 is for obtaining the name of the user.
This is my first week in learning c++ using online videos btw so don't be surprised if you found stupid errors.

so here is the code
main.cpp
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
  #include <iostream>
#include "class1.h"
#include "class2.h"
#include <string>
using namespace std;

int main()
{
   int l;
   int h;
   int o;
   int i;
   int j;
   int k;
   string n;
   cout << "Enter today's day ";
   cin >> l;
   cout << "\nEnter the current month ";
   cin >> h;
   cout << "\nEnter the current year";
   cin >> o;
   cout << "\nEnter the name ";
   cin >> n;
   cout << "\nEnter the day of birth ";
   cin >> i;
   cout << "\nEnter the month of birth ";
   cin >> j;
   class2 ao(l,h,o,i,j,k);
   ao.printData();

}


class1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef CLASS1_H
#define CLASS1_H


class class1
{
    public:
        class1(int d1, int m1, int y1, int d2, int m2, int y2);
        int age(int d, int m, int y, int dd, int mm);
    protected:
    private:
        int days1;
        int months1;
        int year1;
        int days2;
        int months2;
        int year2;
};

#endif // CLASS1_H 


class1.cpp
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
#include "class1.h"
#include <iostream>

using namespace std;

class1::class1(int d1, int m1, int y1, int d2, int m2, int y2)
{
    days1=d1;
    months1=m1;
    year1=y1;
    days2=d2;
    months2=m2;
    year2=y2;

}
int class1::age(int d, int m , int y, int dd, int mm){
    if (months1>12 || months2>12){
        cout << "invalid data";
        return 0;
    }
    mm=months1-1;
    switch (mm){
    case 0 : dd=31;
    break;
    case 1 : dd=31;
    break;
    case 2 : dd=28;
    break;
    case 3 : dd=31;
    break;
    case 4 : dd=30;
    break;
    case 5 : dd=31;
    break;
    case 6 : dd=30;
    break;
    case 7 : dd=31;
    break;
    case 8 : dd=31;
    break;
    case 9 : dd=30;
    break;
    case 10 : dd=31;
    break;
    case 11 : dd=30;
    break;
    default : cout << "invalid data " << endl; return 0;
    }
    y=year1-year2;
    m=months1-months2;
    d=days1-days2;
    if (y<0){
        cout << "invalid data " << endl;
        return 0;
    }

    if (m<0){
        m+=12;
        y--;
    }

    if (d<0){
        d+=dd;
        m--;
    }
    if (d>=dd){
        d-=dd;
        m++;
    }
    cout << " has " << y << " years " << m << " months " << d << " days " << endl;

}


class2.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef CLASS2_H
#define CLASS2_H
#include "class1.h"
#include <iostream>
#include <string>

using namespace std;


class class2
{
    public:
        class2(string x, class1 bd);
        void printData();
    protected:
    private:
        string name;
        class1 birthdate;
};

#endif // CLASS2_H 


class2.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "class2.h"
#include "class1.h"
#include <iostream>

using namespace std;

class2::class2(string x, class1 bd)
: name(x) , birthdate(bd)
{

}
void class2::printData(){

cout << name;
 birthdate.age();


}


Thanks in advance
Last edited on
Your problem is pretty clear. This is your age function -

age(int d, int m , int y, int dd, int mm)
Which takes 5 arguments as paramter.

This is when you call that function.

birthdate.age();
Giving it 0 out of 5 arguments as parameter.
Topic archived. No new replies allowed.