I am writing a program for homework assignment in C++. I am having bit of a problem with passing values from one initialized constructor to the other and it says:
error C2664: 'Book::Book(std::string,Author *,Publisher *,double)' : cannot convert parameter 2 from 'Author' to 'Author *'
I’m a bit rusty in OOP and new to C++.
Please post if I should include more code I will attach code from main class and class from which I cant do the conversion. The program isn’t nearly finished.
Main.cpp
#include <iostream>
using namespace std;
#include "Book.h"
void main()
{
cout << "Book 1" << endl;
Author *pAuthor = new Author("John", "Doe");
Publisher *pPublisher = new Publisher("Wrox", "10475 Crosspoint Blvd.", "Indianapolis");
Book *book = new Book("Memory Management", *pAuthor, *pPublisher, 49.99);
cout << "Book 2" << endl;
int i;
cin >> i;
};
You shouldn’t dereference the Author and Publisher pointers, since the Book constructor expects pointers, not values passed in.
However, when dealing with all those pointers, you could have lots of memory management problems. This would be OK for a small program since all memory is released once the program exits, however getting into the habit of managing your memory correctly is important. If you want to avoid passing by value, maybe you should read about references in C++.