Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode C++ Vectors: Implicit instantiation of undefined template

I ran this code on a different IDE and it was successful. For some reason I get the above error message on Xcode. I assume I'm missing a header of some kind, but I'm not sure which one.

#include <iostream>
#include <limits>
#include <string>
#include <vector>

int main() {
    vector<string> listRestaurants;  // error: Implicit instantiation of undefined template
    return 0;
}
like image 920
Nathan Hale Avatar asked Mar 12 '18 23:03

Nathan Hale


3 Answers

Xcode 10.2.1 was showing me the error Implicit instantiation of undefined template 'std::__1::vector<std::__1::basic_string<char>, std::__1::allocator<std::__1::basic_string<char> > >'.

#include <iostream>
#include <vector>
int main(int argc, const char * argv[]) {
  std::vector<std::string> listRestaurants;

  ....
  return 0;
}

Fixed my issue.

like image 77
Sauvik Dolui Avatar answered Nov 03 '22 08:11

Sauvik Dolui


Didn't realize that #include <vector> is required. I thought it was part of standard library template; I ran this code in VSCODE IDE and it worked fine for me

#include <iostream>
#include <vector>
using namespace std;
int main() 
{
    uint_least8_t i; // trying to be conscious of the size of the int
    vector<int> vect;
    for(i = 0; i < 5; ++i) 
    {
        vect.push_back(i);
    }
    for(auto i : vect) 
    {
        cout << i << endl;
    }
    return 0;
}
like image 38
Stats_Lover Avatar answered Nov 03 '22 09:11

Stats_Lover


If adding std:: is not the issue for you, then check if you have #include <vector>. That fixed the issue for me.

like image 8
Parneet Kaur Avatar answered Nov 03 '22 09:11

Parneet Kaur