[c++]automatic vs dynamic storage

From: ed (nocoo_t2spam_at_yahoo.com)
Date: 03/13/04


Date: Sat, 13 Mar 2004 21:05:06 GMT


Hi. I was wondering if there are any hard and fast rules to go by
when deciding whether to create an object with automatic storage, or
with dynamic storage.

For instance, I may create an object with automatic storage, in some
function/block
in my program. But that object may be passed around all throughout
the program.

Maybe something like:

int myFunc(void)
{
    MyClassName MyObj;
    AnotherClass AnotherObj;

    MyObj.doSomething(AnotherObj);

    // more stuf ......

}

MyObj may pass AnotherObj somewhere else. Is this ok? Or is this a
situation where
you need to use dynamic storage?
I guess what I'm not clear on is, is AnotherObject still considered to
be in the scope
of myFunc, even though it's being passed around to other parts(and
scopes?) of
the program?

tia,
--ed