[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: IMPORTANT: Static objects are evil.
From: Michael Matz <matz () ifh ! de>
Date: 2000-06-29 7:57:15
[Download RAW message or body]
Ho,
On Thu, 29 Jun 2000, Waldo Bastian wrote:
> Static objects are evil. Do not use them. If you really need a static object,
> use a static pointer instead. E.g. like this:
>
> static MyObject *my_static_pointer = 0;
> if (!my_static_pointer)
> my_static_pointer = new MyObject();
To add to that, if you also rely on those objects to be destructed
automatically (which the above fails to do), you need to use normal static
objects, but _don't_ make them local to functions, instead define them at
file global level, like:
static MyObject dont_make_that_local;
int user_func(int) {
do_something_with(&dont_make_that_local);
}
This works on most platforms. But generally of course, don't use them at
all.
Ciao,
Michael.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic