C++运行时类型识别(RTTI)
发布时间
阅读量:
阅读量
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<typeinfo>
using namespace std;
class Base {
friend bool operator==(const Base&, const Base&);
public:
protected:
virtual bool equal(const Base&) const;
};
class Derived :public Base
{
public:
string mem;
protected:
bool equal(const Base&) const;
};
bool Derived::equal(const Base& rhs) const
{
try
{
auto r = dynamic_cast<const Derived&>(rhs);
if (this->mem == r.me
全部评论 (0)
还没有任何评论哟~
