Tuesday, November 27, 2007

Re: C++ Globals Registry Problem

Hello,
  Typically when you need a LIFO (Last-in First-out) data-structure, you'll use a stack (which, yes, can be implemented using a linked list, although you'll probably just want to use the STL class).
I would simply push the function pointers onto the stack as they come, and when it comes time to clean up, pop them all and call the functions in that order.

As for your questions:
1. Yes, iSize is a typo, it should be eSize.
2. This syntax:
  Registry() : iIndex(0) {}
is called an initialization list.  You may use it to call an explicit base constructor, but it can also be used to initialize member variables.  Since iIndex is an int, the code above is simply shorthand for
  Registry() { iIndex = 0; }
If, however, iIndex were an instance of an object, the above code is actually preferred because it prevents the compiler from calling the object's default constructor first.

As for the enum, there is no real point that I know of - it should have the exact same effect as
  const int iSize = 16;
with the added bonus that no one mixes up iSize and eSize ;)

Hope that helps!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to Cpp-Programming@googlegroups.com
To unsubscribe from this group, send email to Cpp-Programming-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Cpp-Programming?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

<< Home