Use function from base class by pointer

I have a problem with segmentation fault (core dumped) when I try to run this code. I don't know when I try to get something from the memory that I can't acces. It seems to compile but I can't find the solution. There is a problem with draw() function from my base class Item.


Weapon* sword = new Weapon("Sword of justice", 15, 300, "text.txt", 35);
vector<string> backpackInv = backpack.showInventory();


void Backpack::addItem(Item* object) {
if(size <= inventory.size()) {

vector<string> Backpack::showInventory(){
string item = inventory[0]->draw();       //there is sth wrong with this command ;(
vector<string> items;

return items;


#include "Item.h"
#include <iostream>

using namespace std;

Item::Item(std::string name, unsigned int weight, double price, string source):
name(name), weight(weight), price(price), source(source){}

string Item::draw()
    ifstream File(source);                                  //Open file

string Lines = "";                                      //Store all lines

if (File) {                                             //Check if everything is good
    while (File.good()) {
        string TempLine;                                //Temp line
        getline(File, TempLine);                        //Get temp line
        TempLine += "\n";                               //Add newline character

        Lines += TempLine;                              //Add newline
    return Lines;
else {
    Lines = "ERROR File does not exist.";               //Return error

File.close();                                           //Close file
return Lines;                                           //Print it to the screen