typeid Operator C++ Specific —>typeid( type-id )typeid( expression )The typeid operator allows the type of an object to be determined at run-time.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.END C++ Specific /////////////////////////////////////////////////////////////// type_info Class C++ Specific —>The type_info class describes type information generated within the program by the compiler. Objects of this class effectively store a pointer to a name for the type and an encoded value suitable for comparing two types for equality or collating order. The encoding rules and collating sequence for types are unspecified and may differ between programs.class type_info { public: virtual ~type_info(); int operator==(const type_info& rhs) const; int operator!=(const type_info& rhs) const; int before(const type_info& rhs) const; const char* name() const; const char* raw_name() const; private: ... }; Note You must include the typeinfo.h header file in order to use the type_info class.END C++ Specific
int nNum = 0 int *pNum = &nNum; cout << typeid(pNum).name() << endl;// output is: // int *
typeof 得到当前变量类型.然后像我写地那样生成该类型地变量.
我不想搞地那样麻烦,想easy一些,我看的C代码.
C++ Specific —>typeid( type-id )typeid( expression )The typeid operator allows the type of an object to be determined at run-time.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.END C++ Specific
///////////////////////////////////////////////////////////////
type_info Class
C++ Specific —>The type_info class describes type information generated within the program by the compiler. Objects of this class effectively store a pointer to a name for the type and an encoded value suitable for comparing two types for equality or collating order. The encoding rules and collating sequence for types are unspecified and may differ between programs.class type_info {
public:
virtual ~type_info();
int operator==(const type_info& rhs) const;
int operator!=(const type_info& rhs) const;
int before(const type_info& rhs) const;
const char* name() const;
const char* raw_name() const;
private:
...
};
Note You must include the typeinfo.h header file in order to use the type_info class.END C++ Specific
int *pNum = &nNum;
cout << typeid(pNum).name() << endl;// output is:
// int *
我这样typeid(&nNum).name() shi;编译器还是不认呀 !!!!