"Patrick" <th**********@spamgourmet.com> wrote in message
news:ck**********@home.itg.ti.com...
Hi
I have a problem in my C++ Funktion. I needed an 2 dimensional Array. For
this i took a template script in order to create the array in the
funktion.
The Size of the Array I have to calculate first before I create it.So I
have
to init it inside my Funktion. Now how do I get this Array so that it is
globally accessible.
Thanx
Patrick
Globals are evil. :-) I'd reconsider that idea, if possible. Do you really
need it accessible by all classes and functions? Perhaps you might consider
having a class that contains both the array object, and any other objects
and code that need access to the array.
Many new programmers start out by writing their programs as one big main()
function, which calls other functions, in a precedural fashion. Using
object-oriented approaches often leads to better code, for many reasons.
Instead, you might want to declare a local instance of this new "container"
class in your main() function, and let it do all the work you now have in
main(). (Assuming that's the way you've structured it, of course...you
haven't shown any code, so I'm guessing.)
At the very least, I'd put the array into a class. Then you can use it
however you please. You can create it in one place, and pass a pointer to
it to other functions that need to work on it. Or you can declare it
global, but wait until your program is ready to "initialize" it, calling a
member function to do the actual creating of the internally stored array.
In any case, wrapping it in a class would be my first task.
-Howard