小编Guy*_*sen的帖子

How do I check if a variable derives from a class?

I want to print variables of many types. I've made a class named IStringable, and some classes that derive from it. In my PrintVariable function I want to check whether the parameter derives from IStringable, and if it does then print it.

class IStringable {
public:
    virtual ~IStringable() { }
    virtual std::string ToString() const = 0;
}

class Person : public IStringable {
public:
    Person(const std::string name) : _name(name) { }
    virtual std::string ToString() const { return _name; …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

8
推荐指数
1
解决办法
146
查看次数

标签 统计

c++ ×1

inheritance ×1