Re: Staic array de allocation



lan collins is right,static member will be deallocated when app
exit,refer below example:
#include <stdio.h>

class CTest
{
public: CTest(){ printf("allocate!\n");}
~CTest(){ printf("deallocate!\n");}
void dosomething(){ printf("do something!\n"); }
};


CTest& return_static();

int main(int argc, char* argv[])
{
CTest& t= return_static();
t.dosomething();
return 0;
}


CTest& return_static()
{
static CTest t;
return t;
}

.



Relevant Pages

  • Re: help: class compile error
    ... > defines a global int i. so I can use ... > class CTest ... reference, unless they somehow _change_ the arguments. ... take its argument by a _const_ reference (unless it intends to change ...
    (comp.lang.cpp)
  • Re: template method gof pattern
    ... Call CTest constuctor before CStrategyBase constructor. ... perhaps you should choose private ... int getI() ...
    (microsoft.public.vc.language)
  • Re: Deleting class instance from static member function?
    ... > class CTest ... > int main ... but it's a little misleading. ... CTest* x = new CTest; ...
    (comp.lang.cpp)
  • Re: implementing composition
    ... > int nn; ... guarantee the lifetime of Array elements, ... The first design stores copies of CTest ...
    (comp.lang.cpp)
  • Re: new operator / define
    ... You could redefine new to New like this: ... void operator delete ... int main ... >> class CTest ...
    (comp.lang.cpp)