Hello friends,
I am trying to access Birthday object from peoples class and display it in main but why the program is getting compilation error?
here is my code
main.cpp
Code:
#include<iostream>#include "Birthday.h"
#include "Birthday.cpp"
#include "People.h"
#include "People.cpp"
using namespace std;
int main(){
Birthday birthObj(11,5,1992);
People JasonSmith("Jason",birthObj);
JasonSmith.printInfo();
return 0;
}
Birthday.h
Code:
#ifndef BIRTHDAY_H#define BIRTHDAY_H
class Birthday
{
public:
Birthday(int m,int d,int y);
void printDate();
private:
int month;
int day;
int year;
};
#endif // BIRTHDAY_H
Birthday.cpp
Code:
#include "Birthday.h"#include<iostream>
using namespace std;
Birthday::Birthday(int m,int d,int y)
{
month = m;
day = d;
year= y;
}
void Birthday::printDate(){
cout<<month<<"/ "<<day<<"/ "<<year<<endl;
}
People.h
Code:
#ifndef PEOPLE_H#define PEOPLE_H
#include<string>
#include "Birthday.h"
#include "Birthday.cpp"
using namespace std;
class People
{
public:
People(string x,Birthday bo);
void printInfo();
private:
string name;
Birthday dateOfBirth;
};
#endif // PEOPLE_H
People.cpp
Code:
#include "People.h"#include "Birthday.h"
#include<iostream>
using namespace std;
People::People(string x,Birthday bo)
: name(x),dateOfBirth(bo)
{
}
void People::printInfo(){
cout<<name<<" was born on ";
dateOfBirth.printDate();
}
Please be easy on me as i am still learning c++