C++静态成员变量退出析构

#include <iostream>
#include <memory>
#include <Windows.h>
using namespace std;
 
class A
{
public:
    A(){
        cout << "create" << endl;
    }
    ~A(){
        cout << "delete" << endl;
    }
};
 
class B 
{
public:
    B() {};
    ~B(){};
 
private:
    static std::shared_ptr<A> m_instance;
};
 
std::shared_ptr<A> B::m_instance = std::shared_ptr<A>(new A());
int main()
{
    B b;
    cout << "end" << endl;
    return 0;
}

虽然如此,但是 chromium 还是报错

加no_destructor可以解决这个 

 https://www.cnblogs.com/wuOverflow/p/4636064.html

 

posted @ 2022-04-20 17:23  冰糖葫芦很乖  阅读(81)  评论(0编辑  收藏  举报