Hi,
I was wondering if someone could help me.
I have a template function where based on the type passed in
I have to possibly access a struct member or just print the value.
Yet when I try to compile this it fails with tons of errors.
How would I go about fixing this?Code:#include <typeinfo> #include <iostream> using namespace std; typedef struct { double a; double b; } A; template<class E> void check_el(E val) { if(typeid(E) == typeid(int)) { cout << val << endl; } else if(typeid(E) == typeid(A)){ double t = val.a; cout << t << endl; } else { cout << "NOTHING" << endl; } } int main() { A a = {1, 2}; check_el<A>(a); check_el<int>(5); return 0; }
Thanks a lot for any help,
Tony



LinkBack URL
About LinkBacks



CornedBee