mercredi 25 février 2015

How can I convert a reference type to a value type?

I'm trying to move some code to templates using the new decltype keyword, but when used with dereferenced pointers, it produces reference type. SSCCE:



#include <iostream>

int main() {
int a = 42;
int *p = &a;
std::cout << std::numeric_limits<decltype(a)>::max() << '\n';
std::cout << std::numeric_limits<decltype(*p)>::max() << '\n';
}


The first numeric_limits works, but the second throws a value-initialization of reference type 'int&' compile error. How do I get a value type from a pointer to that type?


Aucun commentaire:

Enregistrer un commentaire