I am getting a bad access error when the code goes into the assignment operator. Not exactly sure how to write the struct pointer member variable in terms of src.
src.m_myBook is a null pointer; you're dereferencing a null pointer. This is a very bad thing. If you're going to dereference a pointer, make sure it's pointing at the right thing.
struct Book
{
string title;
string author;
Book()=default;//added this two to make work easier.
Book(const std::string& _title,const std::string& _auth):title(_title),author(_auth){}
};
CSNerd &operator = (const CSNerd& src)
{
if(this != &src)
{
m_myName = src.m_myName;
if(m_myBook)///i'd prefer smart pointers over raw ones.
{delete m_myBook; m_myBook=nullptr;}
if(src.m_myBook)///only access src.m_myBook->{element} when the pointer holds address to a valid object, otherwise it will e undefined behavior.
m_myBook = new Book(src.m_myBook->author,src.m_myBook->title);
}
return *this;
}