C++ 教程

C++ 教程 C++ 简介 C++ 入门 C++ 语法 C++ 输出 C++ 注释 C++ 变量 C++ 用户输入 C++ 数据类型 C++ 运算符 C++ 字符串 C++ 数学运算 C++ 布尔值 C++ 条件语句 C++ Switch 语句 C++ While 循环 C++ For 循环 C++ Break/Continue 语句 C++ 数组 C++ 引用 C++ 指针

C++ 函数

C++ 函数 C++ 函数参数 C++ 函数重载

C++ 面向对象

C++ OOP C++ 类和对象 C++ 类方法 C++ 构造函数 C++ 访问修饰符 C++ 封装 C++ 继承 C++ 多态

C++ 高级教程

C++ 文件 C++ 异常处理 C++ 动态内存 C++ 命名空间 C++ 模板 C++ 预处理器 C++ 信号处理 C++ 多线程 C++ Web 编程 C++ 正则表达式

C++ 如何使用

C++ 两个数字相加

C++ 标准库参考

C++ 标准库 - 简介 C++ 标准库 - <fstream> C++ 标准库 - <iomanip> C++ 标准库 - <ios> C++ 标准库 - <iosfwd> C++ 标准库 - <iostream> C++ 标准库 - <istream> C++ 标准库 - <ostream> C++ 标准库 - <sstream> C++ 标准库 - <streambuf> C++ 标准库 - <atomic> C++ 标准库 - <complex> C++ 标准库 - <exception> C++ 标准库 - <functional> C++ 标准库 - <limits> C++ 标准库 - <locale> C++ 标准库 - <memory> C++ 标准库 - <new> C++ 标准库 - <numeric> C++ 标准库 - <regex> C++ 标准库 - <stdexcept> C++ 标准库 - <string> C++ 标准库 - <thread> C++ 标准库 - <tuple> C++ 标准库 - <typeinfo> C++ 标准库 - <utility> C++ 标准库 - <valarray>

C++ 模板库参考

C++ STL 库 - <array> C++ STL 库 - <bitset> C++ STL 库 - <deque> C++ STL 库 - <forward_list> C++ STL 库 - <list> C++ STL 库 - <map> C++ STL 库 - <queue> C++ STL 库 - <set> C++ STL 库 - <stack> C++ STL 库 - <unordered_map> C++ STL 库 - <unordered_set> C++ STL 库 - <vector> C++ STL 库 - <algorithm> C++ STL 库 - <iterator>

C++ 实例

C++ 实例 C++ 练习 C++ 测验



C++ Type_info 库 - operator!= 函数

描述

它返回两个 type_info 对象标识的类型是否不相同。


声明

以下是 std::type_info::operator!= 的声明

C++98

	
bool operator!= (const type_info& rhs) const;

C++11

bool operator!= (const type_info& rhs) const noexcept;

参数

rhs − 它识别对象类型。


返回值

它返回两个 type_info 对象标识的类型是否不相同。


异常

No-throw guarantee − 这个成员函数从不抛出异常。


数据竞争

语言环境对象被修改。


示例

在下面的 std::type_info::operator!= 示例中。

#include <iostream>
#include <typeinfo>
#include <string>
#include <utility>
 
class person {
   public:

      person(std::string&& n) : _name(n) {}
      virtual const std::string& name() const{ return _name; }

   private:

      std::string _name;
};

class employee : public person {
   public:

      employee(std::string&& n, std::string&& p) :
         person(std::move(n)), _profession(std::move(p)) {}

      const std::string& profession() const { return _profession; }

   private:

      std::string _profession;
};

void somefunc(const person& p) {
   if(typeid(employee) == typeid(p)) {
      std::cout << p.name() << " is an employee ";
      auto& emp = dynamic_cast<const employee&&gt;(p);
      std::cout << "who works in " << emp.profession() << '\n';
   }
}

int main() {
   employee paul("sairamkrishna","tutorialspoint");
   somefunc(paul);
}

输出应该是这样的 −

sairamkrishna is an employee who works in tutorialspoint

❮ C++ 标准库 - <typeinfo>