Your Ad Here

Monday, March 9, 2009

Switch case

Hi

it is not really important, but i woul like to know why it dosn't work as intended.

Ist really simpel example (I played a little with typeid operator)

my class:

Code:
---------
template class WhatType
{
public:
WhatType(const T& at) : ct(at) {}
const char* ausgabe() const;
private:
T ct;
};
---------
Function ausgabe()

Code:
---------
template const char* WhatType::ausgabe() const
{
char c = typeid(T).name()[0];
switch(c)
{
case 'i': return "Integer "; break;
case 'd': return "double "; break;
case 'b': return "bool "; break;
case ('p' || 'P'): return "pointer "; break;
case 'c': return "charakter ";break;
default: return "string ";
}
}
---------
and main():

Code:
---------
int main(int argc, char *argv[])
{
WhatType wb(true);
cout << wb.ausgabe() << endl;
WhatType* pwt = &wb;
WhatType*> wp(pwt);
cout << wp.ausgabe() << "Orig: " << typeid(pwt).name()[0]<< endl;
WhatType wi(5);
cout << wi.ausgabe() << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
---------
now I recieve
bool
_string Oring: P_
Integer

Why string?
The case of 'P' or 'p' is pointer and not string!?

Read More...
Your Ad Here

No comments: