compiling the code below with g++ main.cpp functions.cpp -o run gives me the error error: ‘vector’ does not name a type. Declaring namespace at the top of main.cpp usually works across all .cpp files for me.
main.cpp
using namespace std;
#include "functions.h"
main () {}
functions.h
#include <vector>
functions.cpp
#include "functions.h"
vector <int> x;
EDIT: I appreciate the fact all responders know what their talking about, but this normally works for me. Would the use of a makefile have any bearing on that? something else that I might be missing?
Yes but in this example
functions.cpphas not seenusing namespace stdsince you only wrote that inmain.cpp.Don’t add
using namespace stdtofunctions.h, usestd::to qualify types. Adding ausing..imposes an unnecessary burden on the user of your header.