Convert “this” pointer to string

后端 未结 5 1769
夕颜
夕颜 2020-12-14 10:08

In a system where registered objects must have unique names, I want to use/include the object\'s this pointer in the name. I want the simplest way to create

5条回答
  •  抹茶落季
    2020-12-14 10:42

    You could use string representation of the address:

    #include  //for std::stringstream 
    #include   //for std::string
    
    const void * address = static_cast(this);
    std::stringstream ss;
    ss << address;  
    std::string name = ss.str(); 
    

提交回复
热议问题