Mat*_*4Us 2 c++ types pointers object shared-ptr
有没有办法从共享指针获取对象类型?认为:
auto p = std::make_shared<std::string>("HELLO");
Run Code Online (Sandbox Code Playgroud)
我想从 p 中获取字符串类型,例如:
p::element_type s = std::string("HELLO");
Run Code Online (Sandbox Code Playgroud)
含义: p::element_type 是 std::string。
谢谢!
shared_ptr::element_type
shared_ptr
为您提供;所持有的类型 p
您可以使用说明符访问此类型decltype
。例如:
int main()
{
auto p = std::make_shared<std::string>("HELLO");
decltype(p)::element_type t = "WORLD"; // t is a std::string
std::cout << *p << " " << t << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1296 次 |
最近记录: |