Tuesday, November 27, 2007

Re: C++ Globals Registry Problem

On Nov 27, 2007 4:26 PM, BlueRaja <blueraja.admin@gmail.com> wrote:
> 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.

And because the destructor is a function (technically) I could just
throw a function pointer to the destructor, right?

> As for your questions:
> 1. Yes, iSize is a typo, it should be eSize.

I thought so, but I wasn't entirely certain, so I asked. That's the
problem with some of these tutorials... they assume you've already
included things that make strange #define's or typedefs that make
little sense unless you're familiar with the context.

> 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.

That makes sense.

> 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 ;)

Hah, thanks!

--
Registered Linux Addict #431495
http://profile.xfire.com/mrstalinman
John 3:16!

--~--~---------~--~----~------------~-------~--~----~
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