Precompiled header problems

857 views Asked by At
//........Project for ABC.dll
//ABC.h
#pragma once
class ABC{
public:
    ABC(){}
private:
    std::vector<int> m_vector;
};

//ABC.cpp
#include "Stdafx.h"
#include "ABC.h"

//Stdafx.h
#include <vector>

Till today, I've skipped #include <standard-lib.h> in my headers by delegating it to Stdafx.h header.

It's never been a problem when I worked in a single project file.

Now I'm trying to add a new DLL project to gather shared codes in one project.

It compiled well and generated ABC.dll too.

Here's a problem. When another project that uses ABC.dll show compile error saying that std::vector does not exist.

//...........Another Project using ABC.dll
int main(){
    ABC abc;
}

Error C2039 'vector': is not a member of 'std'

To get it working, I had to include all the libraries in the consumer's Stdafx.h too.

Maybe I've been misusing the precompiled header.

I want to know whether the way I've been doing with the PCH was wrong or right.

If it's wrong, I would appreciate it if you suggest right ways of using PCH.

Thanks.

1

There are 1 answers

3
user7860670 On BEST ANSWER

Your problems have nothing to do with precompiled headers. A good practice is to include all the stuff directly used by current file. This will prevent changes in includes of one header file from potentially requiring changes in includes in files that are using this header. vector needs to be included in ABC.h because it is directly used there. Otherwise you'll end up with endless struggling to figure out which headers needs to be included when including this particular library header.