Forward declaration is a technique that has at least 2 purposes:
For purpose #2, a TU (translation unit) that includes header file A but does not use the functions using the class defined in header file B and does not access that class, does not need to include header file B. That way if header file B ever change and forward declaration is used, this TU will not be recompiled. Taking systematically all the opportunities to reduce header file dependencies will not make a big difference on a project containing just a few TUs but it can save hours of compilation on big projects. Also, from experience, it is much easier to plan ahead and think about this aspect as the project grows than trying to remove the dependencies once they become a major problem for maintenance!
The reason why forward declarations work is because the compiler does not need to know the size of a class to generate code that handles pointer or reference to that type. A pointer or a reference always have the same size no matter the type.
Now that I have convinced you of the benefits of using forward declarations in header files, once you start using them, you might stumble on minor difficulties. How to forward declare a class inside a namespace? I have checked into the C++ bible 'The C++ Programming Language' from Bjarne Stroustrup and it remains quiet on the subject.
Fortunately, the answer is simple. Since namespace are open, all you have to do is:
namespace A { // Forward declaration class B; };
For nested classes, you can do it too but at the condition that it is done inside the outer class full declaration.
class B { // Forward declaration class C; };
is ok but
class B; class B::C;
is not. If this is something that you need, you either have to give up the forward declaration of B or move out class C out of B.
I had high expectations about the fruit of the association of 2 authors that I appreciate but the result did not meet these expectations. Basically this book provides 101 rules or guidelines that you can get for free by looking at the table of content. Each of these rules is then followed by a very short explanation (1 or 2 pages usually). In my opinion, most of them are common wisdom that you can get from other sources. This is it. That is all you will get from this book. For that reason, I recommend to skip this one except if a convenient and compact collection of common knowledge is something that you are looking for.
It is not perfect. One complain is that the first part is too easy and is aimed for total beginners and then there is the second part where a lot of material is presented too fast. I wished that the book spent less time with very basic (pun intended) VBA stuff but takes more time to make the transition to more advanced topics smoother.
Other than that, the book contains a lot of code that can easily be reused such as in my C++ tutorial that shows how to automate Outlook from a C++ program.
I have been disappointed by this book. I wanted it mostly to learn how to program Outlook. When I started reading it, I have realized that only a small portion of it was dedicated to Outlook.
Perhaps that I am harsh against the book value because I am not part of the intended readers but I guess that even readers interested to programming Exchange would not find much value of this book. I am saying so because the book is huge close to a thousand pages but it sounds like a cut and paste of the Exchange programmer user manual. When I purchase a book like this one, I expect it to be a complement to the product documentation, to give a better insight of how and why a given software works like it does. This book does not deliver up to these expectations.
The best Outlook programming book that I have found is: Microsoft Outlook Programming, Jumpstart for Administrators, Developers, and Power Users. Skip this one.
You have to know that its target audience is beginner C++ programmers. I am somehow experienced with C++ programming and by looking at the excellent reviews this book got, I had high expectations when I purchased it. I have been disappointed to only have found maybe 2 small advices that I did not know. Reading over 250 pages for a so small reward has been disappointing. If you consider yourself good in C++, my advice is that you should skip this one.
I want you to find in this blog informations about C++ programming that I had a hard time to find in the first place on the web.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
<< < | > >> | |||||
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |