Hi I am currently learning C++ from a book called "C++ programming for the absolute beginner, 2nd edition" and I came by an example in the book that tries to demonstrate the use of vectors. However when I keyed in the code in the example character for character and tried compiling it, I got an error which I couldn't understand.
1> main.cpp
1>c:\users\kenneth\documents\visual studio 2010\projects\testet\testet\main.cpp(49): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\kenneth\documents\visual studio 2010\projects\testet\testet\main.cpp(65): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\kenneth\documents\visual studio 2010\projects\testet\testet\main.cpp(82): warning C4789: destination of memory copy is too small
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\kenneth\documents\visual studio 2010\Projects\testet\Debug\testet.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Can anyone please explain or point to me what might be the problem. I don't understand where the error could have occurred as I am supposed to be learning about vectors in the book and not be able to troubleshoot it already.
Thanks.
I can't test the code myself now, but the first 2 errors look like they are because you are comparing asignedint with anunsignedint. (int is signed, whereas size() returns an unsignedint because the size of the vector is always positive).
Try changing int i = 0; to unsignedint i = 0;.
The third error is not really what it says it is. It's because there is no f[3]. f[] holds 3 objects, so the last element isf[2] not f[3].
Change
1 2
f[3].name="Camel";
f[3].price=9;
to
1 2
f[2].name="Camel";
f[2].price=9;
I'm pretty sure the last error is caused by the other 3. Fix the code and see if it goes away.