V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
auto8888
V2EX  ›  C++

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

  •  
  •   auto8888 · Nov 18, 2020 · 1978 views
    This topic created in 1989 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   ·   2748 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 13:17 · PVG 21:17 · LAX 06:17 · JFK 09:17
    ♥ Do have faith in what you're doing.