V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
northisland
V2EX  ›  问与答

帮我分析一下, 用 C++创建 static 与对象无关的类成员变量, VS2013 的这个问题从哪里来

  •  1
     
  •   northisland · Jun 27, 2017 · 1478 views
    This topic created in 3237 days ago, the information mentioned may be changed or developed.

    原型大概是这样:

    #include<random>
    using std::mt19937;
    using std::uniform_int_distribution;
    
    class Datum3CH {
     protected:
      static mt19937 rng;  // 就是这里,想做一个与对象无关的类成员变量,所有该类对象用同一个随机数生成器。
    }
    

    g++4.9 通过无问题。

    vs2013 能通过编译,链接时显示:

    error LINK2001: 无法解析的外部符号 public: static class std::mersenne_twister_engin<...> Datum3CH::rng*(?rng@?$Datum3CH@M@@2V?$.....)
    

    大概,变量声明了但没找到定义,是这个问题。。。 但这个原因我搞不定。。。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1008 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:18 · PVG 03:18 · LAX 12:18 · JFK 15:18
    ♥ Do have faith in what you're doing.