jeudi 5 avril 2018

Generic way of returning binary data without raw pointers

I have 3 classes like this (psuedocode):

class Parent {
    public:
        virtual void * getData(size_t & size) = 0;
};

class A : public Parent {
    public:
        void * getData(size_t & size) {
            size = sizeof(structA);
            structA * a = new structA();
            //fill er up
            return (void *) a;
        };
};

class B : public Parent {
    public:
        void * getData(size_t & size) {
            size = sizeof(structB);
            structB * b = new structB();
            //fill er up
            return (void *) b;
        };
};

structA and structB are POD C structs that I can't modify (provided by vendor) so I can't create a parent and return a polymorphic unique_ptr for example.

My question is: is there a way to have class A and B generically return their struct data without the use of raw pointers given the constraints I have?

Aucun commentaire:

Enregistrer un commentaire