Unique class type Id that is safe and holds across library boundaries

前端 未结 11 700
离开以前
离开以前 2020-12-06 05:52

I would appreciate any help as C++ is not my primary language.

I have a template class that is derived in multiple libraries. I am trying to figure out a way to uniq

11条回答
  •  旧时难觅i
    2020-12-06 06:08

    What kind of ID? Are you looking for an atomically increasing int? If a string is fine, what about:

    static string s_id()
    {
       return typeid(Foo).name();
    }
    

    If it needs to be an int, but not automatically increasing, you could hash that for a 128-bit integer unlikely to have collisions (though likely a larger number than you need)

提交回复
热议问题