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

前端 未结 11 699
离开以前
离开以前 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条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 06:13

    You can do the following:

    #include 
    
    
    template 
    class blah
    {
    public:
        static const int cid = id; 
    };
    
    int main(int argc, char *argv[])
    {
        std::cout << blah<>::cid << " " << blah<10>::cid << std::endl;
    
    }
    

    I don't know if it's a good idea though. The blah<> part is a bit unintuitive too. Maybe you're better off assigning them ids manually, or you can create a base type, give it a template argument with your class id.

提交回复
热议问题