I have compiled person.h and person1.cpp files successfully. But when I add player1.h and player1.cpp files in my code I get an error.
My main function is:
#include <iostream>
#include "person1.cpp"
using namespace std;
int main(){
Person person1("Metehan Gencer", 100, "Bahcelievler Mah. Hayyam1 Sok. Huzur Apt.");
cout << "person : " << person1 << endl;
return 0;
}
person1.h
#ifndef PERSON1_H_INCLUDED
#define PERSON1_H_INCLUDED
#include <string>
#include <string_view>
using namespace std;
// Base Class
class Person
{
friend ostream& operator<<(ostream&, const Person& person);
public:
Person() = default;
Person(string_view fullname, int age, const string address);
~Person();
// Getters
string get_full_name()const{
return m_full_name;
}
int get_age()const{
return m_age;
}
string get_address()const{
return m_address;
}
public:
string m_full_name{"None"};
protected:
int m_age{0};
public:
string m_address{"None"};
};
#endif // PERSON1_H_INCLUDED
person1.cpp
#include <iostream>
#include "person1.h"
using namespace std;
Person::Person(string_view fullname, int age, const string address)
: m_full_name{fullname}, m_age{age}, m_address{address} {}
ostream& operator<<(ostream& out, const Person& person){
out << "Person [Full name : " << person.get_full_name() << ", Age: " << person.get_age() << ", Address: " << person.get_address() << "]";
return out;
}
Person::~Person()
{}
The Code running as this. But when I add player1.cpp and player1.h files I get an error like this: fatal error: person1.h: No such file or directory| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
player1.h
#ifndef PLAYER1_H_INCLUDED
#define PLAYER1_H_INCLUDE D
//#include <person1.h>
// Player will do public inheritance form Person
class Player : public Person
{
friend ostream& operator<<(ostream& out, const Player& player);
public:
Player();
~Player();
// See the access we have to inherited members from Person
void play(){
m_full_name = "John Snow"; // OK
m_age = 55; // OK
m_address = "ASDFGH;SADFSDG;JHYUKH0";
}
private:
int m_career_start_year{0};
double m_salary{0.0};
int health_factor{0}; // Let's say that it's 0~10
};
#endif // PLAYER1_H_INCLUDED
player1.cpp
#include <iostream>
#include <person1.h>
#include <player1.h>
using namespace std;
Player::Player() {}
ostream& operator<<(ostream& out, const Player& player){
out << "Player[Full name : " << player.get_full_name() << ", age : " << player.get_age() << ", address : " << player.get_address() << "]";
return out;
}
Player::~Player() {}