Convert “this” pointer to string

后端 未结 5 1767
夕颜
夕颜 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:37

    You mean format the pointer itself as a string?

    std::ostringstream address;
    address << (void const *)this;
    std:string name = address.str();
    

    Or ... yes, all the other equivalent answers in the time it took me to type this!

提交回复
热议问题