转换“这个”指针字符串 [英] Convert "this" pointer to string
本文介绍了转换“这个”指针字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在注册对象必须有唯一名称的系统中,我想在名称中使用/ include对象的 this
指针。我想要最简单的方法来创建 ???
其中:
std :: string
您可以使用地址的字符串表示形式:
#include< sstream> // for std :: stringstream
#include< string> // for std :: string
const void * address = static_cast< const void *>(this);
std :: stringstream ss;
ss<<地址;
std :: string name = ss.str();
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 ???
where:
std::string name = ???(this);
解决方案
You could use string representation of the address:
#include <sstream> //for std::stringstream
#include <string> //for std::string
const void * address = static_cast<const void*>(this);
std::stringstream ss;
ss << address;
std::string name = ss.str();
这篇关于转换“这个”指针字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文