When we do a typeid().name() we get the name of the class which the reference or pointer belongs...but something like an id appears....Here I leave my example..
#include <stdio.h>
#include <typeinfo>
#include <iostream>
usingnamespace std;
class Storable{
public:
virtualvoid read() = 0;
virtualvoid write() = 0;
virtual ~Storable() {
}
};
class Component: public Storable{
void write(){};
void read(){};
};
class Transmitter: publicvirtual Component{
public:
void read(){
}
void write(){
}
~Transmitter(){
}
Transmitter(int a):T(a){}
protected:
int T;
};
class Receiver: publicvirtual Component{
public:
void read(){
}
void write(){
}
~Receiver(){
}
Receiver(int b):R(b){}
protected:
int R;
};
class Radio: public Transmitter, public Receiver{
public:
void read(){
}
void write(){
}
~Radio(){
}
Radio(int a,int b):Transmitter(a),Receiver(b){}
};
void f(Storable& ref,Storable* ptr){
cout<<typeid(ref).name()<<endl;
cout<<typeid(*ptr).name()<<endl;
cout<<typeid(ptr).name()<<endl;
}
int main(){
Transmitter objTransmitter(3);
Storable* ptrStorable = &objTransmitter;
f(objTransmitter,ptrStorable);
return 0;
}
the output is:
11Transmitter
11Transmitter
P8Storable
the P word make sense, it means pointer...the names are fine...but the number....It seems like is a classification according to the hierarchy..but how is that?
Returns an implementation defined null-terminated character string containing the name of the type. No guarantees are given, in particular, the returned string can be identical for several types and change between invocations of the same program. http://en.cppreference.com/w/cpp/types/type_info/name
The GNU and LLVM compilers return a mangled name. It can be demangled into a human readable form by filtering it with c++filt, or with the implementation-provided __cxxabiv1::__cxa_demangle() function.
The Microsoft compiler returns a human readable string; no post-processing is required.
I can't compile because the compiler says that free is not a member of std....in general project setting my compiler is gnu c++....
And I'm not familiar with smart pointers...I don't know well what that's doing...as a general idea I get that It's converting a mangled name in a human readable word by activating a macro which cointain demangle....
> the compiler says that free is not a member of std
> And I'm not familiar with smart pointers...I don't know well what that's doing..
> It's converting a mangled name in a human readable word by activating a macro
__cxa_demangle() is a function in the namespace __cxxabiv1
ehheehhe, nice introduction!!!,but the point is, I can have different result about the warnings and errors but the application will be the same for each compiler with the same code...of course respecting what each one can assume....