std::type_info::operator==,std::type_info::operator!= (3) - Linux Manuals
std::type_info::operator==,std::type_info::operator!=: std::type_info::operator==,std::type_info::operator!=
Command to display std::type_info::operator==,std::type_info::operator!=
manual in Linux: $ man 3 std::type_info::operator==,std::type_info::operator!=
NAME
std::type_info::operator==,std::type_info::operator!= - std::type_info::operator==,std::type_info::operator!=
Synopsis
bool operator==( const type_info& rhs ) const;
bool operator!=( const type_info& rhs ) const;
Checks if the objects refer to the same types.
Parameters
rhs - another type information object to compare to
Return value
true if the comparison operation holds true, false otherwise
Example
// Run this code
#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&>(p);
std::cout << "who works in " << emp.profession() << '\n';
}
}
int main()
{
employee paul("Paul","Economics");
somefunc(paul);
}
Output:
Paul is an employee who works in Economics
See also
checks whether the referred type precedes referred type of another type_index
before object in the implementation defined order, i.e. orders the referred types
(public member function)
Pages related to std::type_info::operator==,std::type_info::operator!=
- std::type_info::before (3) - std::type_info::before
- std::type_info::hash_code (3) - std::type_info::hash_code
- std::type_info::name (3) - std::type_info::name
- std::type_info::~type_info (3) - std::type_info::~type_info
- std::type_info (3) - std::type_info
- std::type_index (3) - std::type_index
- std::type_index::hash_code (3) - std::type_index::hash_code
- std::type_index::name (3) - std::type_index::name
- std::type_index::operator==,!=,<,<=,>,>= (3) - std::type_index::operator==,!=,<,<=,>,>=
- std::type_index::type_index (3) - std::type_index::type_index
- std::type_identity (3) - std::type_identity
- std::tan(std::complex) (3) - std::tan(std::complex)