I have a very basic project in VS2012 using precompiled headers. I know that I'm supposed to add all "common" includes to stdafx.h and that I need to include this in each .cpp file. Thus, the basic setup looks like this:
Foo.h:
#ifndef FOO_H
#define FOO_H
class Foo {
public:
Foo();
~Foo();
void do(string str);
};
#endif
Foo.c:
#include "stdafx.h"
#include "Foo.h"
void Foo::do(string str) {}
in stdafx.h:
#include <string>
using namespace std;
Without precompiled headers, I'd put #include <string>
into foo.h, since it has to know about the declaration of string
. But how this foo.h know about string
in this setup? (Note that stdafx.h is only included in the .cpp files).
Note: I have a working example that uses precompiled headers; the question is about how this works.
using namespace std;
in a header file really pollutes the global namespace. Use explicit namespaces instead (e.g. refer tostd::string
) – Joeusing namespace std;
I should usestd:string
whenever I need a string? – mort