Issue With Vectors
Oct 30, 2017 at 10:26pm UTC
I'm writing a program that needs to have three vectors filled in with information, but I keep getting error code C2664 in Visual Studio 2015.
The error message is:
no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=int, _Alloc=std::allocator<int>]" matches the argument list
Here is my vectors function that is meant to fill them in, and also where the errors are originating from.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
void fillVectors(vector<string> &fishShowerTypes, vector<int > &minPond, vector<int > &maxPond)
{
// Filling the fishShowerTypes vector
fishShowerTypes.push_back("1. Shubukin Sprayer" );
fishShowerTypes.push_back("2. Koi Rain Head" );
fishShowerTypes.push_back("3. Sturgeon Rinser" );
fishShowerTypes.push_back("4. Minnow Mister" );
fishShowerTypes.push_back("5. Sunfish Shower" );
fishShowerTypes.push_back("Please enter a number for the shower you'd like. \n" );
// Filling the minPond vector
minPond.push_back("200" );
minPond.push_back("300" );
minPond.push_back("400" );
minPond.push_back("900" );
minPond.push_back("3000" );
// Filling the maxPond vector
maxPond.push_back("400" );
maxPond.push_back("500" );
maxPond.push_back("1000" );
maxPond.push_back("5000" );
maxPond.push_back("10000" );
}
Thanks for any help you can provide! If it helps any, IntelliSense is saying the error is at the period "." before push_back.
Last edited on Oct 30, 2017 at 10:26pm UTC
Oct 30, 2017 at 10:44pm UTC
minPond and maxPond are vectors of ints, and you're pushing strings.
1 2 3
minPond.push_back(200);
minPond.push_back(300);
//(etc.)
Oct 30, 2017 at 10:55pm UTC
Wow, can't believe I didn't notice that! I should probably try to avoid coding while tired.
Thanks, Helios!
Oct 30, 2017 at 11:41pm UTC
Always look for type safety first :)! Probably 80% of errors in beginners code haha
Topic archived. No new replies allowed.