Error occurring in object of your affection project

I have an error that occurs with a lot of text, I created a vector to hold all the hobbies of a profile, and I tested it with small hobbies e.g. “flying” and “gymming” and those worked out fine. “shopping and stuff” also worked out fine, however as soon as I have four items in the vector, I can’t add more without an error occuring, and if I have four items in the vector, I get the error if I make the item in the vector longer e.g. “shopping and stuff and stuff” throws the error. I’m so confused what’s going on and I don’t know what the error means

I can’t copy the error, but it has a lot of memory locations on it and at the end it says “Aborted (core dumped)”

This is my app.cpp file:

#include <iostream>
#include "profile.hpp"
#include <vector>

int main() {

  Profile sam("Sam Drakkila", 30, "New York", "USA", "he/him");
  
  //sam.add_hobby("listening to audiobooks and podcasts");
 // sam.add_hobby("playing rec sports like bowling and kickball");
 // sam.add_hobby("writing a speculative fiction novel");
//  sam.add_hobby("reading advice columns");
  sam.add_hobby("flying");
  sam.add_hobby("gymming");
  sam.add_hobby("shopping and stuff and stuff");
  sam.add_hobby("driving");
  
  std::cout<< sam.view_profile();

}

This is my profile.cpp file:

#include <iostream>
#include "profile.hpp"

	
  Profile::Profile(std::string new_name, int new_age, std::string new_city, std::string new_country, std::string new_pronouns){
    name = new_name;
    age = new_age;
    city = new_city;
    country = new_country;
    pronouns = new_pronouns;
  }


	std::string Profile::view_profile(){
    std::string hob = "Hobbies: ";
    for (int i = 0; i < hobbies.size()-1;i++){
      hob += hobbies[i] + ", ";
    }
   // if(hobbies.size()>=1){
    hob += hobbies[hobbies.size()-1];
    

         
  	return  "Name: " + name + "\nAge: " + std::to_string(age) + "\nCity: " + city + "\nCountry: " + country + "\nPronouns: " + pronouns +"\n" + hob + "\n"; 
    
}

  std::string Profile::add_hobby(std::string new_hobby){
    hobbies.push_back(new_hobby);
    
  }

Hello, @crystallie.

This method doesn’t return anything, nor is it supposed to. It is only used to add hobbies to your vector. What should the return type be? Don’t forget to change it in profile.hpp as well. Happy coding!

1 Like

Thank you so much!!!

1 Like

You are very welcome!