3 ms·
You are repeating yourself if you write class Thing; in every file that uses a Thing. And as I said, that's generally fine. The issue becomes when the decl
by cgrealy 6y ago
You are repeating yourself if you write
class Thing;
in every file that uses a Thing. And as I said, that's generally fine.
The issue becomes when the declaration of Thing includes namespaces, template params, etc. Rewriting that is tedious and error prone.
Look at something like std::string. That's actually
namespace std {
template< class T > struct allocator;
template<class charT> struct char_traits;
template<> struct char_traits<char>;
template<class CharT, class Traits = char_traits<CharT>,
class Allocator = allocator<CharT>>
class basic_string;
using string = basic_string<char>;
}
No-one is forward declaring that.