std::type_info::operator==,std::type_info::operator!= (3) Linux Manual Page
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
employee(std::string &&n, std::string &&p)
: person(std::move(n)), _profession(std::move(p))
{
}
const std::string &profession() const
{
return _profession;
}
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);
}
std::string _name;
};
employee(std::string &&n, std::string &&p)
: person(std::move(n)), _profession(std::move(p))
{
}
const std::string &profession() const
{
return _profession;
}
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:
See also
before object in the implementation defined order, i.e. orders the referred types
