auto8888
V2EX  ›  C++

单例类里不能用模板函数成员吗

  •  
  •   auto8888 · Nov 18, 2020 · 2032 views
    This topic created in 2009 days ago, the information mentioned may be changed or developed.

    经典的单例类

    static CA* Instance(){static CA *instance =new CA() ; return instance;}

    模板函数成员

    template <typename T>

    void creatDB(const std::vector <T> &log);

    编译能过,单例的 Instance()也有值,运行到了 creatDB,this 就变成 0x0 了,然后就崩了。

    2 replies    2020-11-18 14:21:20 +08:00
    wutiantong
        1
    wutiantong  
       Nov 18, 2020
    能用,找别的原因吧
    newmlp
        2
    newmlp  
       Nov 18, 2020
    这和单不单例有啥关系,肯定是其他原因
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 15:11 · PVG 23:11 · LAX 08:11 · JFK 11:11
    ♥ Do have faith in what you're doing.