Skip to content

Recommendation for interfacing rapidjson with polymorphic code? #2381

@Brian-at-Baebies

Description

@Brian-at-Baebies

This is probably a newbish question...but: I have a polymorphic class structure like this:

class Base {
    public:
        virtual void write_json(<Writer-type??>) = 0;
};

class Derived1 : public Base {
    public:
        void write_json(<Writer-type??>) { ... }
};

class Derived2 : public Base {
    public:
        void write_json(<Writer-type??>) { ... } 
};

My classes shouldn't care at all about the specifics of the writer passed in, but since rapidjson heavily depends on CRTP, I either have to declare the function with a fully-specialized Writer object (and lock callers into using only that specialization of Writer) or template the write_json method and lose the polymorphism of my classes.

Is there a recommended approach for gluing CRTP code and dynamic-polymorphic code together?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions