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.cpp has not seen using namespace std since you only wrote that in main.cpp.
Don't add using namespace std to functions.h, use std:: to qualify types. Adding a using.. imposes an unnecessary burden on the user of your header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With