Vectors in c++

I have two classes Book and Author.
1
2
3
4
5
6
7
8
9
10
11
class Book {
private:
    string title;
    string publisher;
    int pages;
    vector<Author*> authors;
public:
    double price{};
    Book();
    Book(const Book& b);
    Book(string t, string p, int pagess, double pricee,vector<Author *> authors);

and class Author
1
2
3
4
5
6
Author(string name, string email, char gender)
{
    n = name;
    mail = email;
    g = gender;
}

In main i have:
1
2
3
4
5
6
7
8
int main() {
    vector<Author *> authors;
    Author a1("Name1","E-mail1",'m');
    cout << a1.toString() << endl;
    Book a("Title1", "Author1", 134, 30, authors a1.toString());
    vector<Book> books;
    books.push_back(a);
      a.print();

I have error on this line:
Book a("Title1", "Author1", 134, 30, authors a1.toString());
error: expected ')' before 'a1'
Can someone help me fix this? I need to call "Author" in Book object...
Book(string t, string p, int pagess, double pricee,vector<Author *> authors);
These are the arguments the code is expecting you to pass in.

Book a("Title1", "Author1", 134, 30, authors a1.toString());
Here, you pass in everything correctly until the end there. I assume you simply want to pass in "authors" without a1.toString() - the constructor is not expecting a string.

Book a("Title1", "Author1", 134, 30, authors);
This ^ is what I assume you wanted.
I want to pass a1 there if possible.. I want to it to print :
Title1 Author 1 134 30 Name1 E-mail1 m
Then edit the constructor:

Book(string t, string p, int pagess, double pricee,vector<Author *> authors);

This is only expecting up to the "authors" variable. You want something like this:

Book(string t, string p, int pagess, double pricee,vector<Author *> authors, string a);

And don't forget to reflect this change in the actual constructor function.

And don't forget the comma between "authors" and a1.toString()
It prints the same.. Only Title1 Author 1 134 30.
I want to use a1 and add it to Book a
You have to edit the constructor to actually print out the string.

You should probably get more familiar with programming. The code isn't going to do anything you don't tell it to.
Topic archived. No new replies allowed.