Define an object from a template type
3 answers
This seems to work fine; use decltype () for C ++ 11; you can try typeof () pre C ++ 11 typeof () in gcc: https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
#include <iostream>
using namespace std;
template<typename T>
struct A {
T *data;
//...
typedef T data_type;
};
int main() {
A<int>::data_type a; // ok
A<int> obj;
decltype(obj)::data_type b; // <-- is it possible to do something like this??
}
+1
source to share