i have an insert function:

template <typename T>
void insert(T item)
{
string T_id = typeid(T).name();
int compare;

if(T_id == "char *")
compare = stricmp(this.item, item);
else
compare = this.item < item;

// ... insert here
}

i'm trying to compare numbers,strings,classes but when T is <char*> i guess i have to use stricmp
instead of comparing with <,> when i compile this it's giving me an error at "compare = stricmp(this.item, item);"
if T is not <char*> how do i get around this or ignore stricmp when T is not char * ... hope this makes sense

Recommended Answers

All 3 Replies

It really helps if you tell us what error message you're getting.

since the result of line 12 sets variable compare to either true or false, then I would think you would want the result of line 8 to be similar, e.g. compare = stricmp(this.item, item) < 0;

ex:1
error C2664: 'stricmp' : cannot convert parameter 1 from 'Employee' to 'const char *'

in this case... i have a class Employee which i have overloaded the operator< . if i comment out compare = stricmp(x,y) and just use compare = x < y it works. but the reason for stricmp is if T is <char *>

ex:2
error C2664: 'stricmp' : cannot convert parameter 1 from 'float' to 'const char *'

here i changed the type from Employee to float

what i'm trying to do is:

if type is (char *)
use stricmp
else
use operator<

what i'm stuck at is when I use other types that stricmp can't work with ie. classes, float, double the compiler complains about the stricmp call.

dragon: i did use compare = stricmp(this.item,item) < 0 ? 1 : 0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.