![]() It seemed to me that there should be a better way to address the problem, but after another round or two of fruitless puzzling, I stopped thinking about the matter. That increased object sizes and also increased runtimes. Cmelik’s and Gehani’s solution involved storing information about the units inside the objects and performing runtime check to detect errors. For example, dividing a distance by time and comparing that to a velocity is fine, but comparing it to an acceleration (which represents distance divided by time squared) is not. They described an approach to detecting units errors in computations involving physical units, e.g., distances, velocities, time, etc. In May 1988, I read the IEEE Software article, “Dimensional Analysis with C++,” by Robert F. Understanding the use of non-type template parameters in Barton’s and Nackman’s approach to dimensional analysis, 1995. I didn’t think there was anything obvious about declaring the implicitly generated functions private in 1988, and I feel the same way in 2006. (At under a page long, it’s possibly the shortest Item in the book.) That I continue to find the insight important is reflected in the fact that I’ve included it in both subsequent editions of Effective C++. When I wrote the first edition of Effective C++ some three years later, this simple insight earned its own Item. Of course! But at the time it was a revelation, a critical step on my understanding of how the pieces of C++ fit together. ![]() Later that day (or perhaps the next day, I don’t remember), John came back and announced that he’d figured it out: the copying functions could simply be declared private. Like the Grinch, 2 we puzzled and puzzled, but none of us was able to find a way to resolve this conundrum. We also knew that the only way to prevent compilers from generating those functions was to declare them manually, but then the functions would exist, and, we reasoned, the objects would again be copyable. We knew that if you didn’t declare the copy constructor and copy assignment operator, compilers would generate them automatically, and the resulting objects would be copyable. There were several of us present, and none of us could figure out how. “How do you keep an object from being copied?,” he asked. One day a fellow graduate student, John Shewchuk, came into the office with a problem he’d been wrestling with. Like many of my friends, I was teaching myself C++ at the time. Realizing that C++’s “special” member functions may be declared private 1, 1988. But I was programming in Pascal at that time, so it doesn’t make the list of my five most important C++-related “Aha!” moments. One revelation of this ilk took place in 1978, when, after a period of struggle, I suddenly realized how pointers work: a computing coming of age if ever there was one. (If not, you’ve made a poor choice of profession.) When those rare moments occur, I can’t help but inhale quickly and freeze, staring off into the distance as if the world, which had heretofore been black and white, suddenly snapped into color. You do this job long enough, you’re going to have a few moments when the big pieces of the puzzle come together, and things suddenly make sense. ![]() In this fifth and final installment, I name my five biggest Aha! moments in C++.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |