error question

I can not find any relevant information on the error I am getting.



1
2
3
Library.cpp:25:33: error: conversion from ‘Book*’ to non-scalar type ‘Book’ requested
       Book btemp = holdings.at(i);


Book is a class in another file
Holdings is a vector.
I want to make a temp holding location for the information at location i

1
2
3
4
5
6
7
8
9
string Library::checkOutBook(string pID, string bID)
{
   for(int i = 0; i < holdings.size(); i++)
   {
      Book btemp = holdings.at(i); 
      if(bID != btemp.getIdCode())  
}
}  

not sure what the error is about.

I read over this
http://www.cplusplus.com/forum/beginner/25109/
and it did not lead to a solution.
Last edited on
I guess the real question boils down to how to I make a temp object so I can run some checks?
What data type is "Holdings" a vector of?
it is
vector <Book*> holdings;
closed account (E0p9LyTq)
vector <Book*> holdings;

A vector containing pointers to books.
holdings is a vectors of pointers. holdings.at() is going to return a reference to a pointer to a Book. Line 5, you can't assign a pointer to a Book to a Book.

You can fix that in one of two ways.
1
2
3
4
  //  1.  Make btemp a pointer.
  Book * btemp = holdings.at(i);  //  Assign a pointer
  //  2.  Dereference the pointer returned by at()
  Book btemp = *holdings.at(i);

number 1 worked just wondering why I need to Dereference the pointer returned by at().
closed account (E0p9LyTq)
holdings.at(i) returns a pointer. You either store that pointer in another pointer, or deference to type (Book).
aaaa ok cool thank you both.
Topic archived. No new replies allowed.