Find what data type typename is

So I want to create a priority_vector class which is like priority_queue for vectors, but, in order to sort strings, I would need to do it differently than I would if I were to do it with numbers, so I need to check whether it is a string or not. How would I do that? This is what I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<vector>
#include<typeinfo>

using namespace std;

template <typename T>
class priority_vector{
public:
T new_stuff;
string new_stuff1;
bool isString(){
if (typeid(new_stuff)==typeid(new_stuff1)){return true;}
else {return false;}
}
};

int main(){
priority_vector <string> new_s;
if (new_s.isString()){ cout<<"It is string type : "; }
else{ cout<<"Not a string type: "; }
return 0;
}
Last edited on
Try checking typeid(variable).name(). http://stackoverflow.com/a/81886
Thanks, it worked.
Topic archived. No new replies allowed.