V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
auto8888
V2EX  ›  C++

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

  •  
  •   auto8888 · 2020-11-18 10:27:48 +08:00 · 1366 次点击
    这是一个创建于 1254 天前的主题,其中的信息可能已经有所发展或是发生改变。

    经典的单例类

    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 条回复    2020-11-18 14:21:20 +08:00
    wutiantong
        1
    wutiantong  
       2020-11-18 11:17:37 +08:00
    能用,找别的原因吧
    newmlp
        2
    newmlp  
       2020-11-18 14:21:20 +08:00
    这和单不单例有啥关系,肯定是其他原因
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2752 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:46 · PVG 23:46 · LAX 08:46 · JFK 11:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.