#include <iostream>
#include "person.h"
#include "PP.h"
using namespace std;
int main()
{
Person person;
PP pp(person);
cout << person.getAge();
}
Person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
class Person
{
private:
string cName;
int cAge;
public:
Person(): cName(""), cAge(0){}
// GETTERS
string getName(){return cName;}
int getAge(){return cAge;}
// SETTERS
void setName(string name){cName = name;}
void setAge(int age){cAge = age;}
};
#endif // PERSON_H
PP.h
#ifndef PP_H
#define PP_H
#include "person.h"
#include "nameRand.h"
class PP
{
private:
Person cPerson;
NameRand nameR;
public:
PP(Person& person):cPerson(person){cPerson.setAge(nameR.getAge());}
void run();
};
#endif // PP_H
nameRand.h
#ifndef NAMERAND_H
#define NAMERAND_H
#include <string>
using namespace std;
class NameRand
{
private:
string rName;
int age;
public:
NameRand():rName("ytvt64f5"), age(1234){}
// GETTERS
string getName(){return rName;}
int getAge(){return age;}
};
#endif // NAMERAND_H
I want the output to be "1234" but its actually "0". Why can't i change the member variables like this? I swear i tried the same thing and it worked as expected but now is not.