- #1
- 90
- 19
This has been bugging me for a while. I suspect the answer is in Sutter or Meyers but I don't own them. Why do so many of the top C++ people say forward declaring templates is bad style or dangerous?
I suggest this article:
http://warp.povusers.org/programming/template_declarations.html
That's a lousy excuse. There is a way around that excuse: The author of the template writes another header where the template is forward declared. Note that the C++ library does this, but only with the C++ I/O. If you have a list as a data member of some class, you need the full implementation anyhow.I have since found the answer by using Google which returned Google's C++ style guide which explains why they don't allow it: Forward declaring a template creates code duplication which prevents the header's owner from making compatible changes to the template.