Person.h
#ifndef PERSON_H_
#define PERSON_H_
/* Person.h */
class Person {
int age;
std::string name;
public:
Person(int, std::string);
std::string getName();
int getAge();
};
#endif /* PERSON_H_ */
The person(int std::string) function declaration uses the std::string name, yet I have not included it in the header file. Thus, I would expect the compiler to complain about the missing symbol. Yet it compiles and runs fine! Why?
The rest of the code...
Person.cpp
#include <string>
#include "Person.h"
Person::Person(int age, std::string name)
{
this->name = name;
this->age = age;
}
std::string Person::getName()
{
return this->name;
}
int Person::getAge()
{
return this->age;
}
Main.cpp
#include <string>
#include "Person.h"
int main() {
printFunc();
Person chelsea_manning(5, std::string("Chelsea Manning"));
}
Also, I am new to C++, so please let me know if you see anything weird about my code / OOP.
#include <string>
from both main.cpp and person.cpp and see what happens ;). – mfontanini