The typeid operator obtains the static type information of the object and returns a type_info object, which contains type name, size, alignment, base class, modifiers and other information. Object information can be accessed through methods such as name(), before(), and base().
Usage of typeid in C
The typeid operator is a C keyword used to obtain the static properties of an object Type information. It returns a type_info object that contains various information about the object type.
Usage:
The typeid operator is followed by an expression that represents the expression whose type information is to be obtained. The expression can be:
Syntax:
<code class="cpp">typeid(expression) // 其中 expression 是要获取其类型信息的表达式</code>
Return value:
The typeid operator returns a type_info object containing the following information about the object type:
You can access the information in the type_info object through the following methods:
Example:
<code class="cpp">int main() { int x; std::string s; std::cout << typeid(x).name() << std::endl; // 输出:int std::cout << typeid(s).name() << std::endl; // 输出:std::__cxx11::basic_string<char> return 0; }</code>
Note: The
The above is the detailed content of Usage of typeid in c++. For more information, please follow other related articles on the PHP Chinese website!