开发者

C++ control order of static member's deallocation

I have a C++ program with a reference-counting smart pointer class. This class works by mapping pointers to reference counts in a static map:

map<ValueIntern*,unsigned int>& ValueRetainMapGetter(){
    static map<ValueIntern*,unsigned int> m;
    return m;
}

The issue that I've been having is that some static variables which I have are being deallocated after the reference map has been deallocated.

My question is: how can I control the order in which the static variables are deallocated so that the map is开发者_开发问答 deallocated after all of the references.


I'd recommend using boost::shared_ptr (or std::tr1::shared_ptr if it's in your tool chain) instead of rolling your own.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜