I’m using a custom library in a c++ project, witch includes several std headers, but when i include the corresponding header in the main file, it’s like i included all the headers in the custom one.
To be clear:
custom header file:
#ifndef CUSTOM_H
#define CUSTOM_H
#include <vector>
//stuff
#endif
Main.cpp:
#include <iostream>
#include "custom.h"
//here, let suppose that i do next:
vector<int> vec;
return 0;
there’s no compile error, like the vector header is included, i want to avoid that, any suggestion
If
custom.h‘s use ofstd::vectoris an implementation detail (and not exposed in the signatures of things you define in the header), consider moving the#include <vector>to the correspondingcustom.cppfile instead.If you can’t move the include out of
custom.hbecause, say, you pass a vector in or out of a method, then it truly is part of your interface and clients of your header will need to know about it.