#include <iostream>
#include <string>
#include <typeinfo>
template<class T>
void print(T var, std::string end="\n"){
std::cout << var << " is of type " << typeid(var).name() << end;
}
template<class T>
class App{
public:
T var;
App(T arg) :var(arg){}
};
class Test{};
int main(){
print("string");
print('b');
print(1.1);
print(1);
App<std::string> obj("obj_str");
print(obj.var);
App<int> obj2(1);
print(obj2.var);
Test o;
App<Test> obj3(o);
std::cout << "o is of type " << typeid(o).name() << std::endl;
}
output being:
1 2 3 4 5 6 7
string is of type PKc
b is of type c
1.1 is of type d
1 is of type i
obj_str is of type Ss
1 is of type i
o is of type 4Test
Why would obj_str be of type Ss, while string is of type PKc?
I assume the output is compiler-dependent. My compiler gives this output:
string is of type const char *
b is of type char
1.1 is of type double
1 is of type int
obj_str is of type std::basic_string<char,std::char_traits<char>,std::allocator<char> >
1 is of type int
o is of type Test
I tried it with Embarcadero C++ Builder. I do use gcc as well and most of the time the two compilers behave in the same way. I wonder what output the Microsoft compiler gives here.