I'm having an issue that so that Book A and Book B's Author and Title will print at the end of the program. So This will verify that the overloaded = is functioning.
#include <iostream>
using namespace std;
class Book
{
public:
Book(char*, char*);
private:
char* title;
char* author;
public:
Book& Book::operator=(const Book& b)
{
if(this != &b)
{
delete [] author;
delete [] title;
author = new char[strlen(b.author)+1];
title = new char[strlen(b.title)+1];
strcpy(author, b.author);
strcpy(title, b.title);
}
return *this;
}
};
int main(int argc, char* argv[])
{
Book* pA = new Book("Aardvark", "Be an Aardvark on pennies a day");
Book* pB = new Book("Speelburgh", "ET vs. Howard the Duck");
pA = pB;
//complete the program so that Book A and Book B's Author and Title print
cout << "The value of Book A's Author and Title are: " << pA.author<<" "<<pA.title<<endl;
cout << "The value of Book B's Author and Title are: " << pB.author<<" "<<pB.title<<endl;
system("pause");
return 0;
}