std::vector segmentation fault during push_back
<p>I have a class named book, that contains books.</p>

<pre><code>#ifndef BOOK_H
#include&lt;string&gt;
#include&lt;vector&gt;
#include&lt;iostream&gt;
#define BOOK_H
class book
{
public:
    std::string Author, Title;
    int Year;
    book(){}
    book(std::string author, std::string title, int year);
    ~book(){}
    void add_book();
    std::vector&lt;book*&gt;library;
};  
#endif
</code></pre>

<p>book.cpp file</p>

<pre><code>#include "book.h"

book::book(std::string author, std::string title, int year)
:Author(author), Title(title), Year(year){} 

void book::add_book()
{
    int y;
    std::string a, t;
    std::cin&gt;&gt;a;
    std::cin&gt;&gt;t;
    std::cin&gt;&gt;y;
    library.push_back(new book(a, t, y));
}
</code></pre>

<p>But when I want to add a new <code>book</code> to the library, I'm getting a segmentation fault during the <code>push_back</code> of the new object in main.cpp file</p>

<pre><code>#include "book.h"

int main()
{
    book* ptr;
    ptr-&gt;add_book();
    return 0;
}
</code></pre>

<p>Could someone explain to me what the problem is?</p>

<p>I'm new in OOP, and though I've read a lot of posts here I still can't find a solution.</p>