Skip to content

adl_serializer and objects sharing an abstract interface. #4401

Closed Answered by gregmarr
jcracine-cimeq asked this question in Q&A
Discussion options

You must be logged in to vote

A couple notes that aren't specific to the library:

class AbstractInterface {
    public:
        virtual unsigned int foobar() = 0;
};

class ImplementationA : public AbstractInterface {
    public:
        // No ; needed after a function body.  This actually creates a separate empty statement
        ImplementationA(unsigned int value): value(value){}; 
        // You need the virtual destructor in AbstractInterface or you won't be able to delete the objects correctly.  Then you don't need to add them explicitly to the derived classes unless you need some special handling.
        virtual ~ImplementationA() = default; 

This is very defensive, but also verbose:

namespace nlohmann{
    t…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jcracine-cimeq
Comment options

@gregmarr
Comment options

Answer selected by jcracine-cimeq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants