获得实例的类名
来源:互联网 发布:网络继续教育报名系统 编辑:程序博客网 时间:2024/05/29 10:01
const type_info& t = typeid(this);
const char* className;
className=t.name();
this 类必须有虚函数(The expression must point to a polymorphic type, that is, a class with virtual functions)
typeid Operator
The typeid operator allows the type of an object to be determined at run time.
Syntax
typeid( type-id )
typeid( expression )
The result of a typeid expression is a const type_info&. The value is a reference to a type_info object that represents either the type-id or the type of the expression, depending on which form of typeid is used. See type_info Class for more information.
The typeid operator does a run-time check when applied to an l-value of a polymorphic class type, where the true type of the object cannot be determined by the static information provided. Such cases are:
- A reference to a class
- A pointer, dereferenced with *
- A subscripted pointer (i.e. [ ]). (Note that it is generally not safe to use a subscript with a pointer to a polymorphic type.)
If the expression points to a base class type, yet the object is actually of a type derived from that base class, a type_info reference for the derived class is the result. The expression must point to a polymorphic type, that is, a class with virtual functions. Otherwise, the result is the type_info for the static class referred to in the expression. Further, the pointer must be dereferenced so that the object it points to is used. Without dereferencing the pointer, the result will be the type_info for the pointer, not what it points to. For example:
class Base { ... };class Derived : public Base { ... };void f(){ Derived* pd = new Derived; Base* pb = pd; ... const type_info& t = typeid(pb); // t holds pointer type_info const type_info& t1 = typeid(*pb); // t1 holds Derived info ...}
If the expression is dereferencing a pointer, and that pointer’s value is zero, typeid throws a bad_typeid exception. If the pointer does not point to a valid object, a __non_rtti_object exception is thrown.
If the expression is neither a pointer nor a reference to a base class of the object, the result is a type_info reference representing the static type of the expression.
- 获得实例的类名
- 获得一个程序的实例名柄
- 获得activity的类名
- 获得对象的类名IOS
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- C#利用反射,遍历获得一个类的所有属性名,以及该类的实例的所有属性的值
- Java反射详解-通过对象或者对象实例获得该对象的包的全名和类名
- 获得类名
- C# 利用反射,遍历获得一个类的所有属性名,方法名,成员名.
- C#基础-获得当前程序的 空间名.类名.方法名
- C#基础-获得当前程序的 空间名.类名.方法名
- 专家访谈:《编译技术》课程教学的一些体会
- 实现从武汉出发,进行34个省会的遍历,最后回到武汉,要求输出遍历路径和最后总里程
- PHP的OOP思维导图
- Pair Programming (结对编程)
- cobol 学习1
- 获得实例的类名
- SBU经营介绍
- cobol学习2
- IE表单在DOM结构被修改后,checkbox和radio取值问题
- devfs,sysfs
- cobol学习3--语法与文法(1)
- cobol学习4--语法与文法(2)
- 大学生PK农民工
- 花点时间搞清top、postop、scrolltop、scrollHeight、offsetHeight