From Titus Winters Discussion on CppCon 2014 :
The big one we learned recently: Forward announcing anything with a template in it is a really bad idea. This has led to problems with the service, as you will not believe. In some cases, a forward declaration may be okay? My suspicion is that the rule will really change to: Library owners are invited to provide a headline that specifically conveys ads that they think are worth (highlighted by me), and you probably shouldn’t make yourself known, and no one will ever must indicate a template type. We'll see. We are still developing [inaudible] details from what we have learned.
So maybe problems with trying to directly jump to declare template types may be one of their motives for discouraging wholesale advertising ...?
Also, providing a “headline that specifically conveys ads that they think is worth it” is similar to the <iosfwd> method, as described here (solution 2.2), here and here .
EDIT:
To be clear, I did not say that I agree or disagree with Google’s disappointment regarding the forward declaration. I was just trying to understand their rationale and made a comment about <iosfwd> .
Personally, I use forward declarations whenever I can, following the directions given later in the same GOTW above (solution 3)
Guideline: Never #include heading when a forward declaration is available.
but Winters' reasoning also seems to have some merit. I was working on code in which I forwarded declared template types from a third-party library, and the syntax became messy (I had not yet encountered the maintenance problems mentioned in Winters). OTOH, I'm not so sure that I will disappoint all the advanced declarations, as stated in the Google C ++ Style Guide, but I think what works for Google?
Disclaimer: I'm not an expert, still a student.
Quokka
source share