ERROR C2664

Jan 3, 2010 at 9:36pm
Hi,

I'm new at this so heres my problem. im creating an online library and im stuck on one part of my code..

When I build solution, it gives me this error "error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'int' to 'const Item &'"

and

"error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)'"

I tried everything to fix it but it just wouldnt work at all.. can anyone help me please?

heres the code

	        int buyNo;
                vector<Item> items;
                bool finished = false;
                cout << "Enter the itemID (Example: 4) Type 0 when you are finished" << endl;
                while (finished == false)
                {
                cin >> buyNo;
error 1 is this line            items.push_back(buyNo);
                    if (buyNo == 0) {
                        finished = true;
                  	
					}
                }

                cout << "You have chosen:" << endl;
                for (int i=0;i<(int)items.size();i++)
                {
Error 2 is this line    cout << items.pop_back() << endl;
                } 



Thank you so much for looking!!!! much appreciated
Last edited on Jan 3, 2010 at 9:40pm
Jan 3, 2010 at 9:41pm
std::vector pop_back returns void.
http://www.sgi.com/tech/stl/Vector.html
Jan 3, 2010 at 9:44pm
error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'int' to 'const Item &'
You're trying to push an int to a vector of 'Item's.

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)'
std::vector::pop_back() doesn't return anything, and you can't send nothing to std::cout.
Jan 3, 2010 at 11:44pm
kbw.. thanks for the link and thanks for helping!!!!!!

helios.. yeh know the problem with the first error but i just dont know how to sort it out, if you can help me with that, that would be great!

THANK YOU GUYS
Jan 4, 2010 at 1:40pm
You need to show us what an Item is. It's not obvious you work out an Item given an ItemID.
Jan 4, 2010 at 3:39pm
For the first error, there is no implicit type conversion available to do the conversion. Implicit type conversions can be created via a single-argument constructor or a conversion operator.

For the second, consider using the vector::back() method for the output before calling pop_back().
Last edited on Jan 4, 2010 at 3:41pm
Topic archived. No new replies allowed.