I am working on using pointers of objects and to be able to use their memory address to pass-over and retrieve information.
My program only passes the title of the book and no other information and I’m not sure why.
How to make that program to store and retrieve information correctly? I am using pointers to pass the values, should I change something in other than main function?
This is my main.cpp file:
#include <iostream>
#include <string>
using namespace std;
#include "Book.h"
int main()
{
system("cls");
Author *pAuthor = new Author("John", "Doe");
Publisher *pPublisher = new Publisher("Wrox", "10475 Crosspoint Blvd.", "Indianapolis");
Book *pBook = new Book("Memory Management", pAuthor, pPublisher, 39.99);
cout << pBook->getBookInfo() << endl;
system("pause");
return 0;
};
book.cpp file:
#include <iostream>
#include <sstream>
using namespace std;
#include "Book.h"
Book::Book()
{
}
Book::Book(string title, Author *pAuthor, Publisher *pPublisher, double price)
{
this->title = title;
this->price = price;
}
Book::~Book()
{
}
You are passing pAuther and pPublisher to the Book constructor, but not doing anything with them.