How to pass a class as an argument to another classes constructor? : <p>The problem i get is inside Person.cpp , in the constructor.When i do this ,everything works ok </p>

<pre><code>Person::Person(string n,Birthday b)
:    name(n) ,
    birthday(b)
{}
</code></pre>

<p>when i do this , i get errors...</p>

<pre><code>Person::Person(string n,Birthday b) {
    name = n;
    birthday = b;
}
</code></pre>

<p>my question is how to pass a class as an argument to another classes constructor?</p>

<p>main:</p>

<pre><code>#include &lt;iostream&gt;
#include "Birthday.h"
#include "Person.h"

using namespace std;

int main()
{
    Birthday birth(13,4,1996);

    Person bill("Billy Par",birth);
    bill.printInfo();
    return 0;
}
</code></pre>

<p>Person.cpp :</p>

<pre><code>#include "Person.h"
#include &lt;iostream&gt;

using namespace std;

Person::Person(string n,Birthday b)
:    name(n) ,
    birthday(b)
{}

void Person::printInfo() {
    cout &lt;&lt; name &lt;&lt; " was born on ";
    birthday.printDate();
}
</code></pre>

<p>Birthday.cpp:</p>

<pre><code>#include "Birthday.h"
#include &lt;iostream&gt;

using namespace std;

Birthday::Birthday(int d,int m,int y) {
    day = d;
    month = m;
    year = y;
}

void Birthday::printDate() {
    cout &lt;&lt; day &lt;&lt; "/" &lt;&lt; month &lt;&lt; "/" &lt;&lt; year &lt;&lt; endl;
}
</code></pre>

<p>Person.h:</p>

<pre><code>#ifndef PERSON_H
#define PERSON_H

#include &lt;string&gt;
#include "Birthday.h"

using namespace std;

class Person {
public:
    Person(string n,Birthday b);
    void printInfo();
private:
    string name;
    Birthday birthday;
};

#endif // PERSON_H
</code></pre>

<p>Birthday.h:</p>

<pre><code>#ifndef BIRTHDAY_H
#define BIRTHDAY_H

class Birthday {
public:
    Birthday(int d,int m,int y);
    void printDate();
private:
    int day;
    int month;
    int year;
};

#endif // BIRTHDAY_H
</code></pre>
