G
Gary Wessle
Hi
can I reference the class name from within the object?
thanks
can I reference the class name from within the object?
thanks
Gary said:Hi
can I reference the class name from within the object?
thanks
Salt_Peter said:yes, typeid()...
#include <iostream>
#include <typeinfo>
struct A {
virtual ~A() { }
};
struct B : public A {
};
int main()
{
B b;
A& r_a = b;
std::cout << "type of r_a: " << typeid(r_a).name() << std::endl;
}
Note: If you remove the virtual d~tor, you loose.
Kavya said:What do you mean by "if you remove virtual destructor you lose"?
Salt_Peter said:yes, typeid()...
#include <iostream>
#include <typeinfo>
struct A {
virtual ~A() { }
};
struct B : public A {
};
int main()
{
B b;
A& r_a = b;
std::cout << "type of r_a: " << typeid(r_a).name() << std::endl;
}
Kai-Uwe Bux said:On my machine, this prints:
type of r_a: 1B
Does not look exactly like the classname to me.
Diwa said:Did some research on this.
See inline.
If on linux, do "c++filt 1B"
This will give unmangled name i.e. "B"
Yes, you are right and anyway "c++filt" is a cmd line programVictor said:Platform-specific information is off-topic.
The 'name' member function of 'type_info' class is NOT guaranteed to
return anything meaningful. It's all compiler-specific and off-topic.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.