class string; // Computer says noThis does not say a lot but what it does say is that string is a class and unfortunately it's not - it's a typedef of basic_string<...>
If I compile a file containing just the line
#include <string>then g++'s -H flag tells me that
#ifndef EG_HPP #define EG_HPP class fwd_string; // instead of #include <string> void eg(const fwd_string &); // instead of // void eg(const std::string &); #endifWhere fwd_string.hpp looks like this:
#ifndef FWD_STRING_HPP #define FWD_STRING_HPP #include <string> class fwd_string { public: fwd_string(); fwd_string(const char *); fwd_string(const std::string &); std::string string; ... }; #endifYou can also use this "type-tunneling" technique to forward declare enums in C. I've never seen this used in anger in an actual codebase. It's just an idea. Caveat emptor.