Pointer Type Search

I want to do something like this:

SomeType *y; /* ... snip ... */ auto x = new decltype(y); // Create a new pointer "x" to a SomeType object. 

But decltype(y) is SomeType* , and decltype(*y) is SomeType& . Is there a way to get a simple SomeType from y ?

+7
c ++ c ++ 11
source share
1 answer

Since decltype(*y) is a link, you can use std::remove_reference :

 new std::remove_reference<decltype(*y)>::type; 
+9
source share

All Articles