Let's say, I declare function_x
by
vector<int> function_x(int i1, int i2);
in function.h, and define it by
vector<int> function_x(int i1, int i2) {
vector<int> vec;
vec.push_back(i1);
vec.push_back(i2);
return vec;
}
in function.cpp.
To use vector, I need to write #include <vector>
in function.h.
If so, I don't need to write #include <vector>
in function.cpp because I put #include "function.h"
anyway and it contains #include <vector>
.
But I feel a little weird because I use vector in function.cpp without including <vector>
(directly).
Is this a normal way to use <vector>
(or any STL container)?
Or, should I write #include <vector>
in function.cpp for explicitness even if I'm sure it's unnecessary? (<vector>
should have include guard)